Game Development Community

Logical testing not working -- what am I overlooking?

by Ray Depew · in Torque Game Builder · 09/29/2007 (9:41 pm) · 4 replies

I'm developing a side-scroller. When the player enters a trigger area, she gets attacked by a snail. The snail's not supposed to move until she enters the trigger area. So the snail has a dynamic field called canMove, which is modified by the player entering and exiting the trigger area:
function HKVTrigger::onEnter(%this, %object)
{
...
	if ( %this == snailTrigger.getID()
			&& %object == player.getID() ) {
		snail.canMove = True;
...
}

function HKVTrigger::onLeave(%this, %object)
{
...
	if ( %this == snailTrigger.getID()
			&& %object == player.getID() ) {
		snail.canMove = False;
...
}

The MoveToward behavior uses canMove to decide whether or not the snail is allowed to move. The problem is that my logical test doesn't work. I tried it four different ways, as you can tell from the commented lines. None of them worked.
function MoveTowardBehavior::onUpdate(%this)
{
...
   //if ( %this.owner.canMove == true ) {
   //if ( snail.canMove == true ) {
   // if ( snail.canMove == 1 ) {
   if ( snail.canMove ) {
	   echo("Blah");
   	%this.owner.moveTo(%this.object.getPositionX(), %this.owner.getPositionY(), %this.speed);
   }
...
}
(This is the MoveToward behavior posted on TDN. Before I inserted the logical test, the %this.owner.moveTo command worked fine, and the snail was chasing the player all over the place, so the problem is not with the %this.owner.moveTo command.

I tried the logical tests from the console, with the game running. When the player was outside the trigger area, here's what I got:
==>echo(snail.canMove);
false
==>echo(snail.canMove == true);
0
==>echo(!snail.canMove);
1
==>echo(snail.canMove == "true");
0
==>echo(snail.canMove == "false");
1

When the player was inside the trigger area, here's what I got:
==>echo(snail.canMove);
True
==>echo(snail.canMove == true);
0
==>echo(!snail.canMove);
1
==>echo(snail.canMove == "true");
0
==>echo(snail.canMove == "false");
1

The capitalization difference between True/true doesn't make any difference.

I tried this one, just for grins:
==>echo(snail.canMove);
True
==>echo(snail.canMove+2);
2

So am I doing something wrong? Or is "True" no longer a logical 1?

#1
09/30/2007 (1:30 pm)
You say the capitalization does not make a difference, but from the console set $temp to true and echo it (you get 1) and then set $temp1 to True and echo it (you get True)

My guess would be if you change your functions to set the canMove to true and false instead of True and False things should work as expected.

Greg
#2
09/30/2007 (9:50 pm)
Son of a gun. It worked.

So the capitalization difference between True and true is critical. Who would have known?

Good thinking, Greg. Thanks for your help.
#3
10/01/2007 (7:02 am)
Language tokens (basically anything you don't write yourself) in TorqueScript are case sensitive. Variable names are not.
#4
10/01/2007 (3:44 pm)
Ah. Learned something new. Thanks, Stephen.