Random numbers

this seems simple, but i am having a hard time doing this. For a class in school i am making a game similar to supermarket sweep. Incase you haven’t seen the show: in order to gain time for shopping you must answer 10 trivia questions at the beginning, but… I DONT WANT ALL OF THE QUESTIONS THE SAME!

*i would like 20 questions to choose from
*i only want 10 questions to show up
*each question different (no repeats)
*after the 10th i would like to go on with the rest of the game

~~:love: i would love anyone even w/sugguestions! and hey… thanks for reading this! SORRY SO LONG :love: emily

put your questions in an array, pic a random question, and remove that question.


questions = ["q1","q2","q3","q4","q5","q6","q7","q8","q9","q10"];

numberOfQuestions = 10;
theQuestion = [];

// run the pick-a-Q 10 times, fastest way
while(--numberOfQuestions-(-1)){
//pick a q and remove it
theQuestion[numberOfQuestions] = question.splice(random(this.length));
}

Now You have an array with the 10 random questions, named theQuestion. If you want a question nr1, use theQuestion[0]. If you want a question nr2, use theQuestion[1]. If you want a question nr3, use theQuestion[2]. Etc.

thanks i know that do while loops would solve the never ending cycle questions. i learned that in visual basic. and i also learned a little bit about arrays last school year. but i’m confused by them still!

well ok… i have 10 labelled frames. each with a question, an answer box, and a check answer button, and clues. i want to keep these 10 frames… but when they click on the check answer button, if correct… i want it to jump to a random labelled frame! (and it does that!) but everynow and then i will get one question more than once. and i can’t get out of my loop!! So what do i need to relabel? the frames? the textboxes? if you need me to… i can send u the file! lol then u can help me! :slight_smile:

PS. you said “If you want a question nr1, use theQuestion[0]” what do you mean by that? i’m confused… if u would please explain slowly in babysteps!

arrays begin with array[0]. The first value will be 0. What he means that is if you want question number 1 then use
theQuestion[0]. Get it?):

How arrays work:

Look at this example:

anArray = new Array();//make an array with the name 'anArray'
anArray[0] = "john"; //fill the first place with the string john
anArray[1] = 12; // fill the second place with the number 12

This means that counting with an array starts with a 0. If you want the first entry, use anArray[0].

A quicker way to writ an array is this:

anArray = ["john",12];

The trick here is to save all the keyframe numbers into an array and remove the number once the question has been showed. Now you pick a random entry from that array and because the question you were already at is no longer there, is will never pick that question.

question = ["label1","label2","label3"];//and so on. This only needs to happen once!!

//to show and remove a question:
frame = question[n = random(question.length)];
question.splice(n);
gotoAndStop(n);

thanks and i’ll try it out and get back to you!
emily :flower:

on (release) {
if (questionbox0 == “lechuga”) {
question = [“question1”, “question2”, “question3”];
// and so on. This only needs to happen once!!
// to show and remove a question:
frame = question[n=random(question.length)];
question.splice(n);
gotoAndStop (n);
} else {
questionbox0 = “try again”;
}
}
<hr>

[COLOR=orangered]^ that is what i used on the button to check the answer to see if it’s correct! and for some reason when i click the button instead of going to the random labelled frame… it goes to the first frame and doesnt move at all. well it mite be easier to get help if you IM’d me or whatever! IM me on: [/COLOR] [COLOR=blue]emilypdavis[/COLOR] [COLOR=orangered]THANKS bunches for trying to explain it to the DuMb BlOnDe![/COLOR]

Whoops. That should’ve been:

question.splice(n);
gotoAndStop (frame);

My bad.

ok the random frame thing works and all. but how would i also have the frames stop after 10? a do while loop? but how what is the code??

:love: LUV EMILY :love":