If statement not correctly checking variable
by Laralyn McWilliams · in Torque Game Builder · 04/05/2010 (4:10 pm) · 2 replies
I'm sure it's a simple mistake... but I'm having trouble spotting it. Here are the relevant code bits:
When I debug, the if statement in playerAttackButton processes the statement even if $battleTurn is not equal to "player." Here's a screen shot showing the code currently past the if statement when the Watch shows the variable is set to "enemy." eluminarts.com/images/tgb/tgb1.jpg
What am I doing wrong? Thanks!
function InitBattle()
{
//coin toss to see who goes first
%coinToss = getRandom(1,2);
if (%coinToss > 1)
{
$battleTurn = "player";
}
else
{
$battleTurn = "enemy";
}
//show turn in placeholder field
turnText.text = $battleTurn;
//hand off to function for whoever won the coin toss
if ($battleTurn == "player")
{
ProcessPlayerAttack();
}
else
{
ProcessEnemyAttack();
}
}
function playerAttackButton::onClick(%this)
{
if ($battleTurn == "player")
{
$enemy1.currentHealth = ($enemy1.currentHealth - $player1.baseAttack);
EnemyHealth.text = $enemy1.currentHealth;
}
}When I debug, the if statement in playerAttackButton processes the statement even if $battleTurn is not equal to "player." Here's a screen shot showing the code currently past the if statement when the Watch shows the variable is set to "enemy." eluminarts.com/images/tgb/tgb1.jpg
What am I doing wrong? Thanks!
#2
Thanks for the quick response. I really appreciate it!
04/05/2010 (4:37 pm)
Ah ha! See, I knew it was something simple. :-)Thanks for the quick response. I really appreciate it!
Torque 3D Owner Sherman Pendley
To compare strings, you need to use $= (equals) and !$= (not equals).