Array referencing problem

  • I am creating a multiple choice quiz within krpano, which has a pool of about 50 questions in xml with names q1,q1,q3 etc. I want to load 8 random questions from that list but check that the question hasnt been loaded before.

    So I created an array storing the question names:

    Code
    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));
    		);

    Then pick a random question and remove it from the array:

    Code
    mul(ranQuestionNum, random, questionArray.count);
    add(ranQuestionNum, 1);
    roundval(ranQuestionNum);
    		
    txtadd(currQuestionName, questionArray[get(ranQuestionNum)].value);
    questionArray.removearrayitem(get(ranQuestionNum));

    So far that works but I cant get the text to populate from the currQuestionName:

    Code
    set(layer[question_text].html, get(questions[get(quizName)].question[get(currQuestionName)].text));

    Any ideas?

  • Pulling my hair out with this one, I can trace it out to be correct but when I try to use it as a reference to load the question I get null. Is it to do with variable type in the array?
    Hopefully someone can help me out

  • Hi,

    instead of:
    txtadd(currQuestionName, questionArray[get(ranQuestionNum)].value);

    try:
    txtadd(currQuestionName, get(questionArray[get(ranQuestionNum)].value));

    or:
    set(currQuestionName, get(questionArray[get(ranQuestionNum)].value));

    or simply:
    copy(currQuestionName, questionArray[get(ranQuestionNum)].value);

    Best regards,
    Klaus

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!