View Full Version : help with some actionscript :)
Steak&Taters
10-31-2002, 12:51 AM
I'm trying to make a game that randomly generates two numbers, checks to see if you enter the correct sum of the two numbers, and then sends you to the appropriate scene, depending on if you are right or wrong.
Two dynamic text boxes show two random numbers. I set the input box variable equal to input. The following actionscript is on the layer with the button you click to check the answer.
on (release) [
na = random(10)
nb = random(10)
answer = na + nb
If (input == answer) [
gotoandplay(scene3:1)
] else [
gotoandplay(scene4:1)
]
]
Am I on the right track, or am I completely clueless? One thing I'm really not sure about is what script should be on what layer. Does it even matter? Thanks.
Rupert
10-31-2002, 01:26 AM
Ok there is probably a better way to do this - but I have just cleaned up what you have done:
on (release) {
// here I just hard coded the number 10 in so you can test it
na = 5;
nb = 5;
//na = random(10);
//nb = random(10);
_root.answer = na + nb;
if (input == _root.answer) {
//gotoAndPlay("scene3", 1);
trace("right");
} else {
//gotoAndPlay("scene4", 1);
trace("wrong");
}
}
Cheers,
Rupert
CyanBlue
10-31-2002, 01:39 AM
Howdy... Welcom aboard... :)
gotoandplay(scene3:1)
This is not a valid syntax for gotoAndPlay() function... If you want to go to the frame 1 of the 'Scene3', then it should be...
gotoAndPlay("scene3", 1);
Check the manual for the right syntax...
When you are reading the manual, check the random() function too... It's been deprecated... Proper usage would be using Math.random() function...
And { ... } should be used where you have used [ ... ], and ';' is missing in your code which is not really recommended to omit...
Your last question... I don't think it really matters... As long as the script is within the range where the Flash can call, it should be fine... What I am saying is... Say that you have a variable called 'theInputValue' inside the movieClip, 'MC_theAnswer'... and if you say something like this in the _level0(or _root), Flash cannot understand what you are trying to say...
if (theInputValue == 10)
This shoud be...
if (_level0.MC_theAnswer.theAnswertheInputValue == 10)
Know what I mean???
The logic... I think you will need to seperate your script...
Frame 1 of your main movie should have a routine that sets the initial value of your two text fields which contain the randome values... and the routine that checks if the user input is correct or not should be resides within the button script that user needs to press after he/she entered the answer...
Right now, you have set na and nb as soon as the button is clicked... If that button is something like 'Start' button, that means the user didn't have time to enter his/her answer into the input box... So, your If (input == answer) will never be true... Or... if that button means something like 'Check Answer' button, that means the initial values for the text fields are not set yet, so the user cannot answer the question, yet you are checking if the your input is the correct answer or not...
How's that??? :)
Steak&Taters
10-31-2002, 09:15 AM
Thanks a ton guys. I realize some of the syntax is wrong, like missing ;'s, sorry about that. They are right in my real script.
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.