Reply LinkBack Thread Tools Search this Thread
Old 04-04-2008, 14:45   #1 (permalink)
gilbs
Registered User
 
gilbs's Avatar
 
Join Date: Nov 2007
Location: UK
Posts: 8
If statement comparing a variable and input...

Hi I'm quite new to all this flash m'larky so forgive me if this seems a bit stupid...

I'm trying to make a basic game where two random numbers are generated and added together, then the user needs to put the answer into an input box in digits and check it. I'm just using "trace" to say whether the answer is right or wrong for the minute.

Im having problems with the check_btn part of the code. I'm trying to simply check if the user has put in the same number as the correct answer but every time it always traces "incorrect" whether it is or not.

I tried declaring userAnswer_txt as a variable and using that in the if statement but had the same problem...

Any ideas???

Code:
start_btn.onRelease = function () { var ran1=Math.ceil(Math.random()*9); var ran2=Math.ceil(Math.random()*9); num1_txt.text=ran1; num2_txt.text=ran2; var answer = ran1 + ran2; answer_txt.text = ran1 + ran2; }; check_btn.onRelease = function () { if (answer == userAnswer_txt){ trace ("correct"); } else{ trace ("incorrect"); } };

Thanks
  Reply With Quote
Old 04-04-2008, 17:06   #2 (permalink)
genitalia
Vagina Vagina Vagina
 
genitalia's Avatar
 
Join Date: Jan 2008
Posts: 181
Is this Numberwang??
  Reply With Quote
Old 04-04-2008, 17:06   #3 (permalink)
genitalia
Vagina Vagina Vagina
 
genitalia's Avatar
 
Join Date: Jan 2008
Posts: 181
No $ symbols in a lot of your variables..
  Reply With Quote
Old 04-04-2008, 17:09   #4 (permalink)
genitalia
Vagina Vagina Vagina
 
genitalia's Avatar
 
Join Date: Jan 2008
Posts: 181
oops is not php.
  Reply With Quote
Old 04-04-2008, 17:45   #5 (permalink)
gilbs
Registered User
 
gilbs's Avatar
 
Join Date: Nov 2007
Location: UK
Posts: 8
Quote:
Originally Posted by genitalia
Is this Numberwang??
lol no its not numberwang... just googled it and now a bit more confused...

It seems nobody knows the answer!
  Reply With Quote
Old 04-04-2008, 18:32   #6 (permalink)
organicfiction
Registered User
 
Join Date: Dec 2007
Posts: 11
Hey gilbs your problem comes from the way flash handles data from textfields. Your code is solid enough so it should work if you change it abit like this:

Code:
start_btn.onRelease = function () { var ran1=Math.ceil(Math.random()*9); var ran2=Math.ceil(Math.random()*9); num1_txt.text=ran1; num2_txt.text=ran2; var answer = ran1 + ran2; answer_txt.text = ran1 + ran2; }; check_btn.onRelease = function () { if (answer_txt.text == userAnswer_txt.text){ trace ("correct"); } else{ trace ("incorrect"); } };
  Reply With Quote
Old 05-04-2008, 12:46   #7 (permalink)
gilbs
Registered User
 
gilbs's Avatar
 
Join Date: Nov 2007
Location: UK
Posts: 8
thanks organicfiction, thats worked a treat!
  Reply With Quote
Old 06-04-2008, 15:36   #8 (permalink)
organicfiction
Registered User
 
Join Date: Dec 2007
Posts: 11
Cheers Glad I could help!
  Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Contact Us - Web Design Forums - Archive - Top
Search Engine Optimization by vBSEO 3.0.0 RC8