| Home | Tutorials | Forums | Articles | Blogs | Movies | Library | Employment | Press | Buy templates |
|
|
#1 |
|
Registered User
Join Date: May 2004
Posts: 3
|
HI... i'm trying to make a "Who wants to be millionaire" flash game. but the questions are allways the same and in the same order.
I had an idea: let Actionscript choose 1 question out of 100... so the question DONT repeat.But the problem is: I dont know how to generate random questions... i just know how to generate random Numbers. plz help |
|
|
|
|
|
#2 |
|
One of many
Join Date: Sep 2002
Location: phoenix
Posts: 268
|
here you go:
//put all your info in an array var myQuestionArray:Array = new Array(); //this right here will create your random number that //will grab your question from the array myQuestions = random(100); //name the time line you are on myTimeLine = this; //your question here: myText_txt.text = myTimeLine[myQuestionArray[myQuestions]]; now that's if you have the questions appear in a text feild. hope that helps |
|
|
|
|
|
|
|
|
#3 |
|
village halfwit
Join Date: Jul 2001
Location: USA, PA
Posts: 3,187
|
I wouldn't recommend picking questions at random since you'll probably end up selecting the same question more than once before you go through all the questions. A better suggestion might be to shuffle the contents of the array then to go through the array in order so you don't repeat any questions.
You should be able to find a shuffle function by searching the forums for "shuffle". -PiXELWiT http://www.pixelwit.com
__________________
There are no answers, only choices. |
|
|
|
|
|
#4 |
|
Flash Connoisseur
Join Date: Apr 2004
Posts: 192
|
I love shuffle functions...this is about the simplest as they come i think
Code:
//pre : send argument of array with numbers of questions
//post : Returns array with numbers provided "shuffled"
function shuffle(numArr):Array {
for(num=numArr.length-1;num>0;num--) {
var myPos = Math.round(Math.random()*num);
var tempVar = numArr[num];
numArr[num] = numArr[myPos];
numArr[myPos] = tempVar;
}
return numArr;
}
|
|
|
|
|
|
#5 |
|
Registered User
Join Date: Jun 2001
Posts: 247
|
If your questions are going to be held in objects than you can do something like this:
Code:
// array to hold all of the questions
questionArray = new Array();
// question object
function QuestionObject() {
// set id to random number
this.id = Math.floor(Math.random()*10000));
this.questionType = null;
this.answeredStatus = null;
this.someParam = null;
}
// create questions
questionArray.push(new QuestionObject());
questionArray.push(new QuestionObject());
questionArray.push(new QuestionObject());
// order array based on random id
questionArray.sortOn("id");
|
|
|
|
|
|
#6 |
|
Addicted To FLASH
|
and from here u gan get a random value from an array and never duplicate the question
http://proto.layer51.com/l.aspx?p=3
__________________
â€* GOD Is Near â€* Questions Don't PM for Questions An eye for an eye, make the whole world blind _____________________________________________GHANDI |
|
|
|
|
|
#7 |
|
Registered User
Join Date: May 2004
Posts: 3
|
hmm where do i put the questions then??? in a text field? in a movie clip?.. i'm new to actionscript. |
|
|
|
|
|
#8 |
|
Registered User
Join Date: May 2004
Posts: 3
|
i got another idea.... HOW can i make the player choose a random frame and play it.... that way i can use multiple choise questions |
|
|
|
|
|
#9 |
|
Addicted To FLASH
|
Code:
var totalFrames = 5
theLevel_btn.onRelease = function(){
_level0.gototAndStop(Math.rounf(Math.random()*totalFrames+1))
}
__________________
â€* GOD Is Near â€* Questions Don't PM for Questions An eye for an eye, make the whole world blind _____________________________________________GHANDI |
|
|
|
|
|
#10 |
|
village halfwit
Join Date: Jul 2001
Location: USA, PA
Posts: 3,187
|
Rather than using "Math.rounf" (with an "F" even
), you would be better off using "Math.floor" since Farafiro's code will occasionally produce 6 as a result. Using "floor" guarantees numbers between 1 and 5.-PiXELWiT http://www.pixelwit.com
__________________
There are no answers, only choices. |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|