Author Topic: Torquescript bug with getWord  (Read 1846 times)

I was confused as to why a piece of my code was acting strangely, and I think I have isolated it down to a bug in the engine.

Here is an example console I/O of the bug.

==>$var1 = "1.3"; //first set up variables
==>$var2 = "1.3";
==>echo($var1 > $var2);
0
==>echo($var1 < $var2);
0
==>echo($var1 == $var2); //everything is as expected
1
==>$var2 = "1.3 junk"; //change this variable with an extra word
==>echo($var1 > getword($var2, 0));
0
==>echo($var1 < getword($var2, 0)); //this seems strange
1
==>$var3 = getword($var2, 0); //lets make a third variable out of the first word of $var2
==>echo($var3); //make sure it is what we expect
1.3
==>echo(strlen($var3)); //no trailing spaces
3
==>echo($var1 == $var3); //looks good
1
==>echo($var1 $= $var3);
1
==>echo($var1 == $var2);
1 //I don't know if this is correct or not, but $var2 is two words
==>echo($var1 == getword($var2, 0)); //run this again to make sure it hasn't changed
0
==>echo($var2);
1.3 junk
==>echo($var1 $= getword($var2, 0)); //Apparently they have the same characters but are not equal
1
==>echo("1.3" + "10.0"); //floating point numbers casting from strings seems to work
11.3
==>echo($var1 == (getword($var2, 0) + 0.0)); //force a cast to decimal before checking equality
0
==>echo(($var1 + 0.0) == (getword($var2, 0) + 0.0)); //force both to be decimals
0
==>echo(($var1 + 0.0) $= (getword($var2, 0) + 0.0)); //they are still the same strings
1


Any thoughts?  Am I crazy or is this definitely a bug?
« Last Edit: July 03, 2015, 05:00:44 PM by Nexus »

It's not necessarily just a bug with getWord(). This is a problem with floating point precision in this game.

According to the TGE source: When you use a float literal, it's actually a double, and when you use a float in a string variable, it gets truncated to float precision, then converted back to a double. This explains the %a = "1.3 blah"; (%a < 1.3) -> true case, because it takes the string and truncates it to something slightly less than 1.3, then converts it back to a double, and then does the comparison, which gives true.

This only applies to variables, using ("1.3 something" > 1.3) will be false because the compiler will optimize the operands and make it a double by default.

These rules are kinda confusing but will give you a basic idea on how to diagnose certain errors. Check out the TGE source for a reference on the TS interpreter, there's all kinds of quirks in there.

Check out the TGE source for a reference on the TS interpreter, there's all kinds of quirks in there.

The TGE source hasn't been released. Are you referring to T3D?

The TGE source hasn't been released. Are you referring to T3D?
No, TGE. Some people grabbed a copy way back when and it's been circulating ever since. T3D should work, but keep in mind there's quite a few considerable modifications to the interpreter.

The TGE source hasn't been released. Are you referring to T3D?

The TGE source was included when purchasing the full license for the engine

The TGE source was included when purchasing the full license for the engine
And hasn't been released otherwise, meaning distribution of it is copyright infringement

No, TGE. Some people grabbed a copy way back when and it's been circulating ever since. T3D should work, but keep in mind there's quite a few considerable modifications to the interpreter.

You're welcome!



And hasn't been released otherwise, meaning distribution of it is copyright infringement

Legally, it should be considered abandonware since they no longer offer it for sale and the version it's been developed into is free. They'd have no case.