Hey everyone,
I built a multiple quiz for a tour about 10 years ago. I recently updated to the krpano (1.20.11). It loads a random question from xml each time and on the first load it works ok but on loading the next question it is returning NAN on the random number (ranQuestionNum). I've been trying to work out what is doing this but can't for the life of me find the problem.
I'm hoping someone could run a pair of fresh eyes over the code please and maybe point out the error.
Any help is much appreciated, thank you
Code
<layer name="multiple_choice" type="container" align="center" x="0" y="0" width="90%" height="90%" zorder="99" scalechildren="true" bgcolor="0x111111" bgalpha="0" bgcapture="false" preload="true" keep="true" visible="false" >
<layer name="quiz_closebtn" url="%CURRENTXML%/skin/icon_close.png" keep="true" parent="multiple_choice" scale="1.0" zorder="98" align="righttop" edge="center" x="15" y="15" onclick="closeQuiz();" />
<layer name="quiz_title" type="text" children="false" parent="multiple_choice" enabled="false" width="80%" zorder="96" align="topcenter" y="20" border="false" background="false" keep="true" />
<layer name="line_quiz" url="%CURRENTXML%/skin/line.png" align="topcenter" parent="multiple_choice" x="0" y="70" width="80%" zorder="91" />
<layer name="question_text" type="text" children="false" parent="multiple_choice" enabled="false" width="70%" zorder="95" align="topleft" y="90" x="10%" border="false" background="false" keep="true" />
<layer name="progress" type="text" children="false" parent="multiple_choice" width="80" zorder="95" align="topright" y="40" x="6%" border="false" css="p {color:#FFFFFF; font-family:arial; font-size:22px }" background="false" keep="true" />
<layer name="a1_text" type="text" children="false" parent="multiple_choice" width="300" zorder="96" align="topleft" y="230" x="17%" background="false" enabled="false" keep="true" />
<layer name="a2_text" type="text" children="false" parent="multiple_choice" width="300" zorder="96" align="topright" y="230" x="5%" background="false" enabled="false" keep="true" />
<layer name="a3_text" type="text" children="false" parent="multiple_choice" width="300" zorder="96" align="topleft" y="350" x="17%" background="false" enabled="false" keep="true" />
<layer name="a4_text" type="text" children="false" parent="multiple_choice" width="300" zorder="96" align="topright" y="350" x="5%" background="false" enabled="false" keep="true" />
<layer name="a1" url="%CURRENTXML%/skin/quiz_btn_a.png" children="false" parent="multiple_choice" width="318" height="85" zorder="95" crop="0|0|318|85" ondowncrop="318|0|318|85" align="topleft" y="200" x="10%" background="false" keep="true" />
<layer name="a2" url="%CURRENTXML%/skin/quiz_btn_b.png" children="false" parent="multiple_choice" width="318" height="85" zorder="95" crop="0|0|318|85" ondowncrop="318|0|318|85" align="topright" y="200" x="10%" background="false" keep="true" />
<layer name="a3" url="%CURRENTXML%/skin/quiz_btn_c.png" children="false" parent="multiple_choice" width="318" height="85" zorder="95" crop="0|0|318|85" ondowncrop="318|0|318|85" align="topleft" y="320" x="10%" background="false" keep="true" />
<layer name="a4" url="%CURRENTXML%/skin/quiz_btn_d.png" children="false" parent="multiple_choice" width="318" height="85" zorder="95" crop="0|0|318|85" ondowncrop="318|0|318|85" align="topright" y="320" x="10%" background="false" keep="true" />
<layer name="quiz_next" url="%CURRENTXML%/skin/gallerybtns.png" keep="true" visible="false" align="bottomright" x="60" y="70" zorder="95" crop="100|0|100|100" onovercrop="100|100|100|100" ondowncrop="100|100|100|100" onup="checkQuestion();" />
<layer name="hint_btn" url="%CURRENTXML%/skin/hint_btn.png" keep="true" align="bottomleft" parent="multiple_choice" x="100" y="90" zorder="95" onup="switch(layer[hint_text].visible);" />
<layer name="hint_text" type="text" children="false" align="bottomleft" parent="multiple_choice" enabled="false" width="50%" zorder="95" y="-176" x="240" visible="false" border="false" background="false" keep="true" />
<layer name="retry_btn" url="%CURRENTXML%/skin/retry_btn.png" parent="multiple_choice" width="318" height="85" zorder="95" crop="0|0|318|85" ondowncrop="318|0|318|85" onup="rebuildQuiz();" align="center" y="0" x="0" visible="false" background="false" keep="true" />
<layer name="quiz_bg_image" url="%CURRENTXML%/skin/bg.png" scale9grid="15|15|930|610" parent="multiple_choice" width="100%" height="100%" zorder="90" align="topleft" keep="true" />
</layer>
<action name="buildquiz">
set(quizName, %1);
set(numOfQuestions, 0);
set(numOfQuestions, get(questions[get(quizName)].question.count));
set(maxNumQuestions, 8);
set(currQuestion, 0);
set(correctAnswers, 0);
set(layer[multiple_choice].visible, true);
set(layer[retry_btn].visible, false);
set(layer[hint_btn].visible, true);
set(layer[progress].visible, true);
for(set(i,1), i LE numOfAns, inc(i),
txtadd(ansLayer, 'a', get(i));
txtadd(ansText, 'a', get(i), '_text');
set(layer[get(ansLayer)].visible, true);
set(layer[get(ansText)].visible, true);
);
switch_hotspots_visibility();
delayedcall(0.3, menu_showhide());
<!-- create array to hold questions used -->
createarray(questionArray);
<!-- store questions in array -->
for(set(i,0), i LT numOfQuestions, inc(i),
set(questionArray[get(i)].value, get(questions[get(quizName)].question[get(i)].name));
);
<!--trace('count: ', get(questionArray.count));-->
showlog();
checkQuestion();
</action>
<action name="rebuildQuiz">
set(maxNumQuestions, 8);
set(currQuestion, 0);
set(correctAnswers, 0);
set(layer[retry_btn].visible, false);
set(layer[hint_btn].visible, true);
set(layer[progress].visible, true);
for(set(i,1), i LE numOfAns, inc(i),
txtadd(ansLayer, 'a', get(i));
txtadd(ansText, 'a', get(i), '_text');
set(layer[get(ansLayer)].visible, true);
set(layer[get(ansText)].visible, true);
);
checkQuestion();
</action>
<action name="checkQuestion">
set(layer[quiz_next].visible, false);
set(layer[hint_text].visible, false);
<!-- increment the question -->
inc(currQuestion,1,maxNumQuestions,0);
setButtons();
if(currQuestion LE maxNumQuestions,
randomQuestion();
,
showResults();
);
</action>
<action name="randomQuestion">
<!-- set random question load -->
sub(arrayNum, questionArray.count, 1);
mul(ranQuestionNum, random, get(arrayNum));
roundval(ranQuestionNum);
set(currQuestionName, get(questionArray[get(ranQuestionNum)].value));
trace('randomQnum: ',ranQuestionNum);
<!-- questionArray.removearrayitem(get(ranQuestionNum)); -->
delete(questionArray[get(ranQuestionNum)]);
<!--txtadd(currQuestionName, 'q', get(ranQuestionNum));-->
loadQuestion();
</action>
<action name="loadQuestion">
<!-- set progress -->
txtadd(progressTxt, get(currQuestion), '/', get(maxNumQuestions));
set(layer[progress].html, get(progressTxt));
<!-- set the current question corr answer -->
set(currCorrectAns, get(questions[get(quizName)].question[get(currQuestionName)].corrAns));
<!-- question -->
set(layer[question_text].html, get(questions[get(quizName)].question[get(currQuestionName)].text));
<!-- hit text -->
set(layer[hint_text].html, get(questions[get(quizName)].question[get(currQuestionName)].hint));
<!-- answers -->
set(numOfAns, get(questions[get(quizName)].question[get(currQuestionName)].answer.count));
for(set(i,1), i LE numOfAns, inc(i),
txtadd(currAnswerNum,'a',get(i),'_text');
txtadd(currAnswerTxt, 'a', get(i));
set(layer[get(currAnswerNum)].html, get(questions[get(quizName)].question[get(currQuestionName)].answer[get(currAnswerTxt)].text));
set(layer[get(currAnswerNum)].css, get(textCss));
set(layer[get(currAnswerTxt)].onup, checkAns(name); setButtons(name););
);
</action>
<action name="setButtons">
for(set(i,1), i LE numOfAns, inc(i),
txtadd(currBtn, 'a', get(i));
set(layer[get(currBtn)].crop, 0|0|318|85);
);
if(%1 != null,
set(layer[get(%1)].crop, 318|0|318|85);
);
</action>
<action name="checkAns">
<!-- check correct answer -->
if(%1 == currCorrectAns,
<!--trace('correct');-->
<!-- increment the correct answer -->
inc(correctAnswers,1,maxNumQuestions,0);
<!--,
trace('incorrect');-->
);
set(layer[quiz_next].visible, true);
</action>
<action name="showResults">
set(layer[quiz_next].visible, false);
set(layer[progress].visible, false);
set(layer[hint_btn].visible, false);
set(layer[retry_btn].visible, true);
for(set(i,1), i LE numOfAns, inc(i),
txtadd(ansLayer, 'a', get(i));
txtadd(ansText, 'a', get(i), '_text');
set(layer[get(ansLayer)].visible, false);
set(layer[get(ansText)].visible, false);
);
if(language == english,
txtadd(feedbackTxt,'Congratulations you have got ', get(correctAnswers), ' of ', get(maxNumQuestions), ' correct![br/][br/]Have another go or try a quiz in one of the other rooms.');
set(layer[question_text].html, get(feedbackTxt));
set(layer[retry_btn].url, '%CURRENTXML%/skin/retry_btn.png');
,
txtadd(feedbackTxt,'Comhghairdeas, tá ', get(correctAnswers), ' amach as ', get(maxNumQuestions), ' ceart![br/][br/]Bain triail as arís nó gabh chuig seomra eile le quiz eile a thriail.');
set(layer[question_text].html, get(feedbackTxt));
set(layer[retry_btn].url, '%CURRENTXML%/skin/retry_btn_irish.png');
);
</action>
<action name="closeQuiz">
set(layer[multiple_choice].visible, false);
switch_hotspots_visibility();
set(questionArray.count, 0);
</action>
Display More