I'm trying to make a game where you have to answer the math problems then press enter. I got the problems generated, but for some reason when I press enter, it goes to the first slide instead of the 4th. Can anyone help?
So there are 2 sections in the question. num1 and num2 (variables and instance name)
the answer box is called ans12.
On the screen, it looks like this: num1 + num2 (the random generated numbers)
Then, I made a little button and it says that when you press enter, it will go to the next problem if you got it right. If you got it wrong, it will go to the game over screen.
This is how I coded it. on (keyPress "<Enter>"
{ if(ans12_txt.text == num1+num2) { nextFrame(); }else{ gotoAndStop(1); //change to right gameover frame } }
That's because ans12_txt.text is a a String where num1+num2 is a Number. You'll either have to convert the number into a string or convert the string into a number (though it's more likely to exceptions).
While I can't exactly remember how it's done in AS2, I believe it's the same as in AS3... basically, instead of your line if(ans12_txt.text == num1+num2) you use if(ans12_txt.text == String(num1+num2))
This should convert the resulting number of num1+num2 to a string, after which you can compare it with the ans12_txt.text! Hope this helps!
That doesn't work. Sorry. It still doesn't go to the next frame. It goes to the first frame instead, where the else code is. I think it says that the answer is wrong, so it will gotoAndStop frame 1.
Try casting (DataType(datatoCast)) or using the toString method (Number.toString()). You might have to make a string comparison, though I haven't done something like this in a while.
I used your first and second help but sadly it didn't work. These are the errors from the compiler. : Statement block must be terminated by '}' if (Key.isDown(Key.ENTER)){
Statement must appear within on handlerif (Key.isDown(Key.ENTER)){