Game Development Community

Confused by script comparison

by Drethon · in Torque Game Builder · 05/27/2009 (2:36 pm) · 6 replies

I'm trying to set an object to 0 initially then put a string in it (my solution probably should be starting with an empty string but bear with me). When I dump the data and the comparisons of the object I get this result

HULL : ST1400
HULL == 0 : 1
HULL != 0 : 0

What is happening here that is causing a comparison of a script object that is set to ST1400 (a datablock internal name) as compared to 0 to evaluate to true?

#1
05/27/2009 (2:42 pm)
You don't set it to ST1400, you set is as a type of such. Its still 0 until you initialize it.
#2
05/27/2009 (2:44 pm)
actually i think you set it to the string "ST1400".
in torquescript, a single word (ie no spaces) doesn't need to be quoted.
you then are using numeric comparison. "==" and "!=" compare two integers, while "$=" and "!$=" compare strings. the final piece of the puzzle is that when a string (that is not a number) is evaluated as a number, it's zero.
#3
05/27/2009 (2:45 pm)
also, the actual torqueScript you're using might be helpful to post in a case like this.
#4
05/27/2009 (4:18 pm)
Already blew away that code for string comparisons before you responded as that seemed like the right answer and that works. The point I had missed is a string always evaluates as 0, not like C treats it as a pointer.

Thanks.
#5
05/27/2009 (4:40 pm)
the log commonly points that out in nice red if you compare strings to ints
#6
05/27/2009 (4:42 pm)
Hmm, didn't see anything in the log about that...