View Full Version : [AS2] Random quiz
salim_designer
09-04-2008, 11:08 AM
I am working on a quiz game and the questions are comming from XML file. I want the questions to appear randomly. I can do that by using Math.random, but I don't want any questions to be repeated, but I Math.random does not solve the problem, because it does not store the questions that has already appeared.
How can I do that?
Psycrow
09-04-2008, 01:35 PM
You could store the questions that have already been shown in an array. Then the next time you pick a question from your XML file you could check if it's in that array. If it is you pick another one. If not... you use it... (and store it in the array).
Or.. you could go through your XML file and make an array with a number of elements equal to the number of the questions. And each element of the array will store a value, indicating if the question has been used....
Something like
myArray[0] = 0;
myArray[1] = 0;
myArray[2] = 0;
.....
You will do that in a loop of course. Then if let's say you pick the 5th question you will check what's the value of myArray[4]. 0 will indicate that you could use it and 1 that you have already used it. If it's 0 then you change it to 1 and use the question...
salim_designer
09-04-2008, 05:57 PM
That's great! I will try the code and let you know if I face any problem.
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.