Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > General > Gaming and Game Development

Reply
 
Thread Tools Rate Thread Display Modes
Old 05-18-2004, 06:01 PM   #1
Blackshark
Registered User
 
Join Date: May 2004
Posts: 3
Default [AS2] how to generate Random Questions for a game?

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
Blackshark is offline   Reply With Quote
Old 05-18-2004, 06:18 PM   #2
exactpixel
One of many
 
Join Date: Sep 2002
Location: phoenix
Posts: 268
Default

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
exactpixel is offline   Reply With Quote
Old 05-18-2004, 07:49 PM   #3
pixelwit
village halfwit
 
pixelwit's Avatar
 
Join Date: Jul 2001
Location: USA, PA
Posts: 3,330
Default

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.
pixelwit is offline   Reply With Quote
Old 05-18-2004, 08:47 PM   #4
Drakkon
Flash Connoisseur
 
Drakkon's Avatar
 
Join Date: Apr 2004
Posts: 195
Default

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;
}
Drakkon is offline   Reply With Quote
Old 01-12-2012, 04:44 AM   #5
jocelynx
Registered User
 
Join Date: Jan 2012
Posts: 7
Default

Hey guys, I am newbie in flash. Im working on this quiz game whereby the player will shoot the correct balloon. When the player shoot the correct answer , the score will increase by 1. The player also have to complete the quiz within the time limit of 10 seconds.

Now my problem is , I dont know how to store the questions and answers in the xml file and make it appear on my flash game.

I have also attached how the game is like in this thread.
Please advise!! Much appreciated!
jocelynx is offline   Reply With Quote
Old 05-19-2004, 01:18 AM   #6
mpol777
Registered User
 
mpol777's Avatar
 
Join Date: Jun 2001
Posts: 247
Default

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");
Each object gets a unique id and then using the sortOn array method it reorders them based on that id.
mpol777 is offline   Reply With Quote
Old 05-19-2004, 05:50 AM   #7
farafiro
Addicted To FLASH
 
farafiro's Avatar
 
Join Date: Dec 2001
Location: Egyptian in UAE
Posts: 12,436
Send a message via MSN to farafiro Send a message via Yahoo to farafiro
Default

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 . Thanks
An eye for an eye, make the whole world blind
_____________________________________________GHANDI
farafiro is offline   Reply With Quote
Old 05-23-2004, 03:44 PM   #8
Blackshark
Registered User
 
Join Date: May 2004
Posts: 3
Default =(



hmm where do i put the questions then??? in a text field? in a movie clip?.. i'm new to actionscript.
Blackshark is offline   Reply With Quote
Old 05-23-2004, 03:50 PM   #9
Blackshark
Registered User
 
Join Date: May 2004
Posts: 3
Talking

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
Blackshark is offline   Reply With Quote
Old 05-24-2004, 03:20 AM   #10
farafiro
Addicted To FLASH
 
farafiro's Avatar
 
Join Date: Dec 2001
Location: Egyptian in UAE
Posts: 12,436
Send a message via MSN to farafiro Send a message via Yahoo to farafiro
Default

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 . Thanks
An eye for an eye, make the whole world blind
_____________________________________________GHANDI
farafiro is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 12:53 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.