Need help with this array format

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
p0ntif
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 18
Joined: Fri Mar 15, 2013 4:41 pm

Need help with this array format

Post by p0ntif » Wed Jul 16, 2014 6:57 pm

Ok, I have been playing around with arrays and am trying to figure out why this does not work.

What I have is a small quiz applet that asks 9 questions using a group of 4 radio buttons ("Answergroup") and keeps track of the score (each button being worth 0-3 points). What i want to do is at the end, display each question and the score for each question as a summary on the last card.

I have all of the questions as strings prestored in an array designated as qArray[x]["question"] where x is the question number. and I am trying to further utilize that array by placing the points into qArray[x]["iscore"] where a numerical value is placed into each corresponding 'iscore". So for example, qArray[1]["question"] should be associated with qArray[1]["iscore"] and then I want to display these at the end of the quiz with

Question 1.- Score
Question 2 - score

etc.

Currently, the way I am building my score array and also grabbing the score from the radio button is with a "next question" button on the quiz applet, so that when one hilites a radio button, they can press next question and the score will be grabbed and stored into 2 variables (1/ qTab which is the sum of all the points, and the array qArray[x]["iscore"], which is the individual score for each question.

The nextbutton code is as follows:

Code: Select all

global qTab, qNbr, qArray
on mouseUp
   add the last word of the hilitedButtonName of group "AnswerGroup" to qTab
   put the last word of the hilitedButtonName of group "Answergroup" into qArray[qNbr]["iscore"]
   nextQuestion 
end mouseUp
Where qNbr is the variable used to increment for each question (from 1-9)

and NextQuestion is the following handler on the card:

Code: Select all

command nextQuestion
   global qNbr, qArray, qTab
   if qNbr > 9 then go to card "Last"
else
   put qArray[qNbr]["question"] into fld "Question"
   add 1 to qNbr
   set the hilitedButtonName of group "AnswerGroup" to empty
end if
end nextQuestion
However, while i am able to populate the questions at the end of the quiz, I cannot populate the scores, and i cannot find what I am doing wrong. I tried just populating single array contents, but it wont even do that, which brings into question my entire method. If someone can provide me with some insight here, I would appreciate it. If you need to see the whole code (card, stack, and objects) I can provide that too. Thanks in advance!

phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

Re: Need help with this array format

Post by phaworth » Wed Jul 16, 2014 8:13 pm

Don't see anything obviously wrong with what you're doing. I'd suggest stepping through the code that increments the score in the array in debug to make sure your array is being updated correctly.

Maybe post the code you're using to display the results too since the problem may be in it rather than in the array updating code.

Pete

p0ntif
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 18
Joined: Fri Mar 15, 2013 4:41 pm

Re: Need help with this array format

Post by p0ntif » Fri Jul 18, 2014 12:32 am

phaworth wrote:Don't see anything obviously wrong with what you're doing. I'd suggest stepping through the code that increments the score in the array in debug to make sure your array is being updated correctly.

Maybe post the code you're using to display the results too since the problem may be in it rather than in the array updating code.

Pete

Thanks for your suggestion, after playing with it for a few hours, I figured out a different way of doing it that worked. :)

Post Reply