Game Development Community

If/else not evaluating properly?

by Jason Swearingen · in Torque Game Builder · 08/13/2005 (2:51 am) · 3 replies

This is using the "Basic Tutorial" torquescript code.

for my enemy fxSceneObject2D's i add the .shipType field and set it to "enemy"

then in the OnCollision() function i check for this, and if it's an enemy, i make a big explosion.

However, the problem is a big explosion is ALWAYS triggered, meaning that the IF is always evaluating to true... any help?

function fxSceneObject2D::onCollision( %srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts )
{
	// Create an explosion for the collision that just occurred
%toLookFor = "enemy";
%foundValue = %dstObj.shipType;
echo("========");
echo(%foundValue);

if(%foundValue == %toLookFor )
{

	createBigExplosion( %dstObj );
}
else
{
	createExplosion( %dstObj );
}

#1
08/13/2005 (3:57 am)
String comparison operator is $= so try:

if (%foundValue $= %toLookFor)
{
  createBigExplosion(%dstObj);
}
else
{
 createExplosion(%dstObj);
}
#2
08/13/2005 (7:13 pm)
Thank you for that info Toby!
#3
09/15/2005 (2:19 pm)
I was having that problem, too. Thanks for both the question and the answer!