Game Development Community

Simple Logic Problem! :-(

by Valerie Butler · in Torque Game Engine · 07/14/2009 (8:10 am) · 2 replies

Hi, I have a very simple problem, its seems very basic! Maybe there is something I am not doing or noticing that somebody else might see first off! I have a GUITextControl called ScoreCounter and during gameplay it is set to "Go To Exit!!" like so...ScoreCounter.setText("Go To Exit!!"); and everything works fine and it changes! Now when I enter a trigger at the end of my game I execute the following code...

if (ScoreCounter.text == "Go To Exit!!")
{
MessageBoxOK("End", "WELL DONE YOU COMPLETED THE MAZE AND COLLECTED ALL THE ITEMS!!", "finishGame();");
}
else
{
MessageBoxOK("End", "YOU HAVE NOT COLLECTED ALL THE ITEMS... GET BACK IN THERE!!!", "doNothing();");
}

The problem is that even if the text is not "Go To Exit!!" the first block of the if statement is always executed for some reason! Its not changed from "Go To Exit!!" by anything since it is set! Its strange! Can anybody see a problem with my logic or syntax? All this code is in script! Thank you for any help! :-)

#1
07/14/2009 (8:14 am)
Yes. Use "$=" (string equality) instead of the usual "==" (numerical equality).

(edit)

... also.. you might want ScoreCounter.getText() instead of just directly querying the value "text".

(ScoreCounter.getText() $= "Go To Exit!!")
#2
07/14/2009 (8:18 am)
Lord, I didnt even have time to scratch myself, thanks for the rapid quick reply! That works! Thank you scott! :-)