Game Development Community

TorqueScript, strcmp() and documentation

by Tim Doty · in Torque Game Builder · 03/25/2005 (3:32 pm) · 5 replies

This is just an observation: the documentation I have on TorqueScript gives what appears to be incorrect information for strcmp(). It states that:

strcmp(one,two)
-Returns a numeric value (1 being TRUE and 0 being FALSE)

stricmp(one,two)
-Returns a numeric value
< 0 "one" is less than "two"
0 "one" is equal to "two"
> 0 "one" is greater than "two"

The behavior in T2D of strcmp() appears to be reversed

#1
03/25/2005 (3:41 pm)
More specifically:

$one="c";
$two="a";
echo(strcmp($one,$two));
> 1
$two="c";
echo(strcmp($one,$two));
> 0
$two="e";
echo(strcmp($one,$two));
> -1
$two="C";
echo(strcmp($one,$two));
> 1

So it appears to have the behavior of stricmp, except for being case sensitive.
#2
03/25/2005 (3:46 pm)
Very very cool... didn't notice that... was going to write my own compare to check if case sensitive (currently when I save out my Torque DB I have it compare each letter to an encrypted version and write that out and then decrypt it on read... but since TorqueScript is not case-sensitive it would lowercase it all... with this I can fix that :)
#3
03/25/2005 (3:46 pm)
That's probably correct.

The Torquescript functions are just wrappers to the actual C++ functions dStrcmp and dStricmp
#4
03/25/2005 (3:54 pm)
Yeah, I'm not surprised by that. But silly me actually looked up the function in the documentation and assumed it was correct. It took me a minute to realize what was going on.
#5
10/30/2007 (7:43 am)
Actually, and i'm not sure if you using TGE script or TGB script (or if even they are different in this case)
but i just tested this 'stricmp' function and for me it is returning the number of places from $a to $e;

for example:

$a="a";
$b="b";
$e="e";

echo(stricmp($a,$b));
-1

echo(stricmp($a,$e));
-4

for the record, I did this in TGB