Game Development Community

Torque script symbol "?

by Russ Martinez · in Torque Game Engine · 11/04/2005 (8:24 am) · 7 replies


#1
11/04/2005 (8:27 am)
The first root main that is written in chapter 4 has this line of code,

$pathList = $addonList !$= "" ? $addonList @ ";control;common" : "control;common";

What is the significance of the "?" symbol. I could not find it on the complete script symbol list.
#2
11/04/2005 (8:49 am)
The $ symbol means the variable is a global variable available to all scripts and functions. other variables are local so they're only accessible to the function they appear in. make sense?
#3
11/04/2005 (8:50 am)
It is a conditional

booleanExpression ? if True do this : if False Do this;
#4
11/05/2005 (9:40 am)
Thanks for the reply,
One thing I noticed about the '?' operator is that it seems to only work in this type of context. I unsuccessfully tried to use it like this:

(1 >= 0) ? $string = true: $string = false;
echo($string);

But when combined with an assignement operator and a comparative operator it works fine:
$num = 1 >= 0 ? $valueA: $valueA;

Thanks again for the reply.
#5
11/05/2005 (10:23 am)
As long as whatever comes before the ? evaluates to 0 or 1, it should work.
#6
11/05/2005 (11:29 am)
Yes, Intuitively speaking it should work that way, however if you use it you will notice that it will only work when the assignment operator is also used.

$someVariable = 1 ? $var = 100 : $var = 200; // $var is successfully assigned 100.
echo($var); // output will be 100

1 ? $var = 100 : $var = 200; // $var is NOT assigned 100
echo($var); // output is blank.

Just an observation. Thanks for the input.
#7
11/05/2005 (4:10 pm)
Oh, you were talking about that one...:)