There's lots of ways you could do this. As Klaus says, the method of storing your questions (and the corresponding answers) makes a difference.
One way is to put the questions and answers into custom property sets of the stack or card, etc. Something like this is a quick and easy way, given a card with two fields ("fldQuestion" and "fldAnswer") and two buttons "Reset" and "Question":
Code: Select all
for the button Reset:
on mouseUp
put empty into field "fldQuestion"
put empty into field "fldAnswer"
repeat with i = 1 to 36
set the QuizQuestions[(i)] of this stack to "Question" && i
set the QuizAnswers[(i)] of this stack to "Answer" && i
put i & cr after tQList
end repeat
delete char -1 of tQList
set the cQList of this stack to tQList
end mouseUp
This will create new Custom Property Sets "QuizQuestions" and "QuizAnswers" with a numeric key for each element in the custom property set. Each key of QuizQuestions indexes the question (which I have dumped in automatically to insert "Question 1", "Question 2", etc. and similarly for QuizAnswers. You can populate the custom property sets (both QuizQuestions and QuizAnswers) according to your list of questions and answers - reading line by line from a file say (although if you already have them written in a textfile, maybe the random selection could/should just read that file directly, rather than use the custom property set approach. See... lots of ways to think about it.)
It also creates/resets a custom property for the list of available question numbers that have not already been used in this session.
Code: Select all
for the Question button:
on mouseUp
put the cQList of this stack into tQList
if the number of lines of tQList is zero then
answer "Out of questions"
else
put any line of tQList into tQLine
delete line lineOffset (tQLine, tQList) of tQList
set the cQList of this stack to tQList
put the QuizQuestions[(tQLine)] of this stack into field "fldQuestion"
put the QuizAnswers[(tQLine)] of this stack into field "fldAnswer"
end if
end mouseUp
First the available question numbers list is read from the custom property cQList. If there are no more questions that have not already been asked then it bypasses the questions, otherwise it will pick "any" line of that list and then delete it, and then put that newly shortened list back into the custom property ready to read next time around. The random question number that was picked is then read in from the QuizQuestions property set. For example, if line 20 was picked, then the value in that line is put into tQLine. First time around it will be 20. Line 20 is then deleted and the shortened list stored again. QuizQuestions[20] is then put into the question field. QuizAnswers[20] is also put into the answer field.
(More realistically you would have the user type in the answer and then do something like check that field contains the same value as QuizAnswer[20] but how you set out your interface and the actions is up to you.)
Next time around, there will be 35 lines in the list of available questions. For argument's sake, line 20 could be randomly chosen again, but this time the value on that line will be 21 (as the value 20 was deleted last time). Again it will be shortened and stored, so that you don't use the same question another time until the list is reset.
Anyway, this is all basic rubbish dumped into the custom properties, but I hope you see how you can tailor that to your needs and methods. Again, there's no
definitive way to do this - other people may come up with different solutions.
HTH anyway.