Why does TorqueScript use a different operator for comparing strings?

Author Topic: Why does TorqueScript use a different operator for comparing strings?  (Read 2140 times)


I don't understand, post your code so we can help.

On a serious note, if you want to know, ask the guys over at garage games who wrote the language.

I'm actually not sure what you're asking
a) why does torquescript use both == and $= as comparative operators
b) why does torquescript use $= where other languages (not specified which ones) use just ==

A lot of languages do it.

I'm actually not sure what you're asking
a) why does torquescript use both == and $= as comparative operators
b) why does torquescript use $= where other languages (not specified which ones) use just ==
he wants to know b

My answer is because it's stupid


Everything in Torque is a string, so you have to tell it if you're treating it as a string or a number.

Everything in Torque is a string, so you have to tell it if you're treating it as a string or a number.

Which is also why we can get away with stuff which, in any strongly typed language, would have the compiler screaming bloody murder at us.

Which is also why we can get away with stuff which, in any strongly typed language, would have the compiler screaming bloody murder at us.
Interesting, can you post an example?

Well here's one simple example used by basically everyone making a list ever. It isn't actually a compiler error but it sure as hell wouldn't do what you would want it to do.

%stuff = "Stuff blah blah";
%pos[-1+%count++] = %stuff;

In TS, the result of this is %pos0 becoming "Stuff blah blah".
In basically every other language I've known ever, this would result in %pos-1 becoming "Stuff blah blah".

"%count++" means "do this after everything else has already been run."
"++%count" means "do this BEFORE anything else gets added or run."

%stuff = "Stuff blah blah";
%pos[-1+%count++] = %stuff;

In TS, the result of this is %pos0 becoming "Stuff blah blah".
In basically every other language I've known ever, this would result in %pos-1 becoming "Stuff blah blah".

How so? Regardless of the order that the sides are evaluated in, practically every language every with a ++ operator that can be used in an expression increments it, then yields the new value. Sure, with your example, any decent language would throw an undefined variable exception, however looking apart from that:

%count++ => 1
-1 => -1

1 + -1 => 0

Interesting, can you post an example?

%a = "a" @ 1;
%obj.setName(7);
echo(5 / "foo");

-snip-

No no, you misunderstand. (Let's assume that %count is predefined as 0 because exceptions.)

-1+(++%count) = -1 + (%count has already been incremented, so 1) = 0, as would be expected.
-1+(%count++) = -1 + (%count does not get incremented until AFTERWARDS, so 0) = -1, which forgets stuff up.

%count still becomes 1 in both cases, but in one case it's done before the addition and in one case it's done after.

No no, you misunderstand. (Let's assume that %count is predefined as 0 because exceptions.)

-1+(++%count) = -1 + (%count has already been incremented, so 1) = 0, as would be expected.
-1+(%count++) = -1 + (%count does not get incremented until AFTERWARDS, so 0) = -1, which forgets stuff up.

%count still becomes 1 in both cases, but in one case it's done before the addition and in one case it's done after.

Well I don't see how that's a flaw of the language, it's just how it's designed. TorqueScript does not have ++x, only x++, and pre-incrementing seemed the most practical when adding it.

function Add(%num1, %num2)
{
   return echo("The result is" SPC (%result = %num1 + %num2)) + %result;
}


echoes and returns the result at the same time, perfect example of how everything in torque is a string.