Game Development Community

Large ints treated as strings?

by Fyodor -bank- Osokin · in Torque Game Engine · 12/01/2007 (2:42 pm) · 1 replies

At one point I need to keep a "settings" in a variable, let's say it's %current
It's holding an integer and being set like:
%current = 0; // Integer!
   for (%i=0;%i<32;%i++)
   {
      if ( someChecks )
         %current |= bit(%i); // Still integer!
   }

At one point I have two variables: %current and %new
If the largest bits "are in" then the number become large, something like 2147450879.
And, if I do normal comparison - if the %current differs from %new I get NO, but I'm sure they differ (in this case with some small bits like 0, 1, 2, 3 and 5.

I think this "long" integer is treated as a string in TS parser, so I have:
// %current = 2147483647
   // %new = 2147483631
   if (%current == %new) echo("Cur:" SPC %current SPC "New:" SPC %new SPC "= Equal!");
   else echo("Cur:" SPC %current SPC "New:" SPC %new SPC "DIFFERS!");
The output:
Cur: 2147483647 New: 2147483631 = Equal!

Btw calling
echo(%current - %new);
will always return zero, as you doing subst a "string" from another "string"

I know, I know, TorqueScript isn't perfect.
Two ways:
Do comparision using $= and !$=
OR
Use the m64 math lib fors subs/adds