Game Development Community

If problem

by CodingChris · in Torque Game Engine · 01/12/2007 (5:34 am) · 4 replies

Hi,
I feel very bad, I want to use if statements and it does not work. I tried to fix the error, but it doesn't work. I fee l silly now. So, please help me. I cannot see the error.
I have this code:
$mode = "Race";
...


if ($mode = "Race") 
{
disconnect();
}

#1
01/12/2007 (5:48 am)
Try this:
if($mode $= "Race")
{
   disconnect();
}
$= Is used for comparing string values.
#2
01/12/2007 (5:51 am)
Thanks
#3
01/12/2007 (6:05 am)
And = is used for declaring variables, not comparing them. Can't remember if this is the case only in C++ or in TS as well, but keep it in mind.
#4
01/12/2007 (6:13 am)
Correct Stefan

Comparing numerical values:
%number = 3;
%testBool = 1;

if(number == 3)
{
     if(testBool != 0)
          echo("Both comparisons succeeded!");
}

String comparisons:
%playerOne = "Michael";
%playerTwo = "Stefan";
%tempString = "Michael";

if(%tempString $= "Michael")
        echo("tempString contains playerOne name");

if(strcmp(%playerOne, %playerTwo))
       echo("I just used the strcmp function");

TDN Script Reference