Game Development Community

Simple If statement.. why isn't it working?

by Steve Howson · in Torque Game Engine · 09/14/2005 (11:38 pm) · 3 replies

Hey all!
Ok, I have a trigger setting the value of a global variable ($buildType) to "Ice" if your in the trigger or "Snow" if you're outside the trigger area. In a trigger.cs script.

I have another script (builditems.cs) that builds either a snowball or iceball depending on that variable.
So within the build function, I'm calling another function to make that determination by doing - buildWhat();.. this is what the function looks like so far:
function buildWhat()
{
	//determines weather to build snowball or iceball, depending on 
	// the trigger variable.
	
	if ($buildType == "Ice")
	{
		echo("Built iceball");
		return;
	}
	else
	{
		commandToServer('BuildSnowball');
		echo("Built snowball");
		return;
	}
}

Now, for what ever reason.. it ALWAYS says "Built iceball" in the console.
I've checked the value of $buildType in the console during the game, and it's keeping the correct values.

I just can't figure out why it's not working.. it's like the if statement is being ignored.
I can set it to anything like... if ($builType == "blah blah blah") and it still does the same thing.

Does anyone have any idea why it's not working?
Both triggers.cs and builditems.cs are in game.cs with the exec command.

Thanks for any help.
Steve

EDIT: Just realized it's goofy to have those returns in there, but took them out and it didn't make a difference with my problem.

#1
09/14/2005 (11:40 pm)
Need to do

if ($buildType $= "Ice")


$= is the string comparisson
#2
09/14/2005 (11:43 pm)
Oh jeez.. can't believe I did that.

Thanks a lot Matthew!
Steve
#3
09/19/2005 (9:33 am)
Happens to us all :)