Game Development Community

Error with if statment

by Nathan Bowhay - ESAL · in Torque Game Engine · 07/14/2006 (11:45 am) · 2 replies

This is a function in inputHandler.cs in the RTS. The problem is in the if(CommandMenu.visible == "0").
What happens is I will rightclick it will show, but then I should be able to right click again and have it disappear. The only to problems I can think of is that immediately as it goes to set it to 0 it sets it to 1 somewhere else (Very unlikely). The second thing I think it could be is that the command menu has it's own inputHandler that makes this code not even run, but I can't find it anywhere.

function GuiRTSTSCtrl::onRightMouseDown(%this, %obj, %x, %y, %z)
{
//echo(%obj.getClassName() @ "right clicked on");
%this.setCommandState("None");
%this.selectionLocked = false;
switch$(%obj.getClassName())
{
case "RTSUnit":
%this.onRightMouseDownUnit(%obj);
case "TerrainBlock":
%this.onRightMouseDownTerrain(%x,%y,%z);
}

if(%this.selectionIncludesTeam == true){ //if units are selected and commandmenu isn't visible make it
if(CommandMenu.visible == "0"){
CommandMenu.position = VectorSub(canvas.getCursorPos(),VectorScale(CommandMenu.extent,1/2)); //command menu moves to cursor position
CommandMenu.visible = "1";
}
else{
CommandMenu.visible = "0";
}
}
}

Please Help!
Thank you for any help you can give!

#1
07/14/2006 (11:51 am)
The comparison needs to be a string comparison, $=, instead of ==, for variables that are set to strings. Otherwise use the integer 1 and 0 to set the value of CommandMenu.visible.
#2
07/14/2006 (12:19 pm)
Thank you!
That makes sense.

Even when changed it still doesn't seem to work it will display in the mouse position and be visible, but whenever I go to right click again it just shows in the new position instead of setting visible to "0" (like there is no else).

Here is the new statement:
if(%this.selectionIncludesTeam == true){ //if units are selected and commandmenu isn't visible make it
if(CommandMenu.visible $= "0"){
CommandMenu.position = VectorSub(canvas.getCursorPos(),VectorScale(CommandMenu.extent,1/2)); //command menu moves to cursor position
CommandMenu.visible = "1";
}
else{
CommandMenu.visible = "0";
}
}

I have tried bool values for all 3 (== for if), int's, and strings. none will work.