PDA

View Full Version : Input box IF statements



jose3760
January 28th, 2008, 06:55 PM
Hello again!
Im having a problem running an if statement for finding out if what the user has typed into the input box matches what the cheat code actually is.
Im adding a cheat to my game, so the user needs to type it into the input box, press send, and hope it works. The input box is also inside of a move clip.

Heres the code on the send button...



on(release){
if(_root.cheats.text == "speedster"){
trace ("speedster");
}else if(_root.cheats.text == "thechosenone"){
trace ("thechosenone");
}else if(_root.cheats.text == "multiplier"){
trace ("multiplier");
}else{
trace ("**** didn't work");
}
}




basically what happens is if I copy, lets say speedster, and then paste it into the input box and press send it will come up with "**** didnt work" every time
I think its pretty simple to fix, but I cant figure out how.
Thanks! =)

parkerdc
January 28th, 2008, 11:19 PM
http://www.serendip.org/inputbox.jpg
Properties of input box

NOTES:
- You might want to convert the cheat text to lower case before you check it.
- You could use Instance Name or var for getting text values.


If you use the Instance Name: I have set to cheats1. (Shown in RED)

on(release){
if(_root.cheats1.text == "speedster"){
trace ("speedster");
}else if(_root.cheats1.text == "thechosenone"){
trace ("thechosenone");
}else if(_root.cheats1.text == "multiplier"){
trace ("multiplier");
}else{
trace ("**** didn't work");
}
}
If you use the var: I set to cheats2. (Shown in YELLOW)

on(release){
if(_root.cheats2 == "speedster"){
trace ("speedster");
}else if(_root.cheats2 == "thechosenone"){
trace ("thechosenone");
}else if(_root.cheats2 == "multiplier"){
trace ("multiplier");
}else{
trace ("**** didn't work");
}
}

jose3760
January 29th, 2008, 12:07 AM
Thanks for the reply!
The problem was that since the input box was inside of an mc i needed to refrence it in the if statement, uhh.. like so :

I had:

if(_root.cheats.text == "speedster"){

but it needed to be:
if(_root.options.cheats.text == "speedster"){