IF statement: string check
by Danny Duggan · in Torque Game Engine Advanced · 04/24/2010 (9:08 am) · 0 replies
Hi,
I'm sure the solution is obvious but I can't seem to solve my problem. I am trying to get an if selection statement to check a string value but I can't seem to get it to work.
function AIBasicDB::think(%this,%aiPlayer){
%object = object.getPosition();
%inArcOfSight = %aiPlayer.CheckArcOfSight(%object);
%range = %this.getRange(%aiPlayer, %object);
%aiPlayer.state = "NORMAL";
echo("STATE == " SPC %aiPlayer.state);
if((%aiPlayer.state == "CAUTIOUS") && (%inArcOfSight)){
echo("THINK ECHO CAUTIOUS");
echo("STATE == " SPC %aiPlayer.state);
}
else if((%aiPlayer.state == "NORMAL") && (%inArcOfSight)){
echo("THINK ECHO NORMAL");
}
else if((%aiPlayer.state == "CONFIDENT") && (%inArcOfSight)){
echo("THINK ECHO CONFIDENT");
}
else if((%aiPlayer.state == "PANIC") && (%inArcOfSight)){
echo("THINK ECHO PANIC");
}
else{
%aiPlayer.getDataBlock().schedule(4000, "find", %aiPlayer);
}
%aiPlayer.getDataBlock().schedule(2000,"think",%aiPlayer);
}
As you can see the coding should cause the echo to relate to the set state of the ai player. However at the moment the result is that the echo announces that the state is normal, followed by the cautious echo, followed by asserting the state is normal. What am I missing - im sure it must be that the first if statement isn't properly checking the %aiPlayer.state value... Any help?
Sorry figured it out $= not ==, thanks anyway
I'm sure the solution is obvious but I can't seem to solve my problem. I am trying to get an if selection statement to check a string value but I can't seem to get it to work.
function AIBasicDB::think(%this,%aiPlayer){
%object = object.getPosition();
%inArcOfSight = %aiPlayer.CheckArcOfSight(%object);
%range = %this.getRange(%aiPlayer, %object);
%aiPlayer.state = "NORMAL";
echo("STATE == " SPC %aiPlayer.state);
if((%aiPlayer.state == "CAUTIOUS") && (%inArcOfSight)){
echo("THINK ECHO CAUTIOUS");
echo("STATE == " SPC %aiPlayer.state);
}
else if((%aiPlayer.state == "NORMAL") && (%inArcOfSight)){
echo("THINK ECHO NORMAL");
}
else if((%aiPlayer.state == "CONFIDENT") && (%inArcOfSight)){
echo("THINK ECHO CONFIDENT");
}
else if((%aiPlayer.state == "PANIC") && (%inArcOfSight)){
echo("THINK ECHO PANIC");
}
else{
%aiPlayer.getDataBlock().schedule(4000, "find", %aiPlayer);
}
%aiPlayer.getDataBlock().schedule(2000,"think",%aiPlayer);
}
As you can see the coding should cause the echo to relate to the set state of the ai player. However at the moment the result is that the echo announces that the state is normal, followed by the cautious echo, followed by asserting the state is normal. What am I missing - im sure it must be that the first if statement isn't properly checking the %aiPlayer.state value... Any help?
Sorry figured it out $= not ==, thanks anyway