I'm trying to make a maths game where two numbers are randomly generated and you have to add them together and type the answer into a input field. The thing is that it always says the answer is wrong.
Here is the code:
//Write random numbers in the text boxes TextBox_txt.text = random(100); TextBox1_txt.text = random(100);
//Sets the yes and no MC's visibility to false Yes_mc._visible = false; No_mc._visible = false;
//Check to see if the answer is right or wrong Go_mc.onRelease = function() { if (Answer_txt.text == TextBox_txt + TextBox1_txt) { Yes_mc._visible = true; }else{ No_mc._visible = true; } }
I would just like to know what it isn't working, thanks.
(Caveat: I don't do AS2, so I might be getting some things wrong.)
Answer_txt.text == TextBox_txt + TextBox1_txt
That's your problem. TextBox_txt and TextBox1_txt are objects. Obviously, you want TextBox_txt.text and TextBox1_txt.text.
However, you've still got another problem after that. "+" in a string context is concatenation, not addition. In other words, 5 + 2 gives you 7, but "5" + "2" gives you "52". So you need to convert them to numbers before trying to add them. I'm not sure of the syntax to do that in AS2 off-hand.
that kool... i have a friend at school that did the same thing but you drag numbers to the answers box... it was challenging but we did it... now its just a friggen assignment thing... lol