Game Development Community

Quick player movement question

by Holmida · in Torque Game Builder · 08/30/2011 (11:27 am) · 2 replies

Hi, some quick question. I want my player object to run when I press the movement keys, and I want him to walk when I press movement + other key ("k", for example). This is how I've done this:

function playerClass::onLevelLoaded(%this, %scenegraph)
{
     $player = %this;
      
      moveMap.bindCmd(keyboard, "left", "playerLeft();", "playerLeftStop();");
      moveMap.bindCmd(keyboard, "right", "playerRight();", "playerRightStop();");
      moveMap.bindCmd(keyboard, "space", "playerJump();", "");
      
      moveMap.bindCmd(keyboard, "k", "setBoolValue();", "setBoolValueRelease();");
      
      
      %this.enableUpdateCallback();
}

function setBoolValue()
{
   $booleano = true;
}

function setBoolValueRelease()
{
   $booleano = false;
}

Now some little pieces of code inside the player movement functions:

if ($booleano = false)
{
    %this.setLinearVelocityX(-30);
}else
{
    %this.setLinearVelocityX(-15);

}
if ($booleano = false)
{
    %this.setLinearVelocityX(30);
}else
{
    %this.setLinearVelocityX(15);
}

The thing is, when I add the "k" and boolean lines and functions to the code, the player ALWAYS walks instead of running. It seems that the bool variable is always at "true", but I can't see why. Any ideas?

Than you all in advantage.

#1
08/30/2011 (12:49 pm)
Your if statements are $booleano = false instead of $booleano == false. You are doing an assignment instead of a compare.
#2
08/30/2011 (12:55 pm)
Oh, such a noob mistake... thank you very much xD I didn't see it.