Game Development Community

Problems with strings and if/else statements

by amaranthia · in Torque Game Builder · 11/06/2006 (3:18 pm) · 2 replies

I'm not quite sure what I'm doing wrong, but no matter what I do, this statement always evaluates true, even though it shouldn't.

%this.type = "p";


if (%this.type = "e")
{
     guiType.setText(%this.type);
}

Okay, what's weird about this is that %this.type shouldn't be evaluated true by this if statement, but when I run my game, it:

a) evaluates true
b) goes through the if statement
c) updates the guiType, and displays "p" to the user.

I don't know what I'm doing wrong... :O

#1
11/06/2006 (4:16 pm)
The line should read:

if (%this.type $= "e")

Use $= to compare strings, and == to compare numbers. = is only used for assignments.
#2
11/06/2006 (10:39 pm)
Ahhhh! Thank you!! :D