Game Development Community

BindCmd parsing error?

by David Taylor · in Torque Game Builder · 07/12/2006 (5:01 am) · 2 replies

I used the input interaction tutorial to bind commands to the keyboard, but it gave me syntax errors. So I adjusted the code ever so slightly, and the errors went away. However, I now have parsing errors, and they seem to occur now and then - there doesn't seem to be a hard and fast rule with when it will work, and when it won't. Can anyone see what I've done wrong here?

function Player::onLevelLoaded(%this, %scenegraph)
{
    $player = %this;

    new ActionMap(playerInputActionMap);
    playerInputActionMap.bindCmd(keyboard, "a", rotatePlayerLeft, stopRotatePlayerLeft);
    playerInputActionMap.bindCmd(keyboard, "d", rotatePlayerRight, stopRotatePlayerRight);

    playerInputActionMap.push();

    echo("PLAYER CREATED!");
}

function rotatePlayerLeft()
{
    $player.setAutoRotation(-25);
}

function stopRotatePlayerLeft()
{
    $player.setAutoRotation(0);
}

function rotatePlayerRight()
{
    $player.setAutoRotation(25);
}

function stopRotatePlayerRight()
{
    $player.setAutoRotation(0);
}

The best I ever had was the player rotating to the left, but not stopping when I let go of the 'A' key. Very, very odd.

#1
07/12/2006 (6:12 am)
Try:
playerInputActionMap.bindCmd(keyboard, "a", "rotatePlayerLeft();", "stopRotatePlayerLeft();");
playerInputActionMap.bindCmd(keyboard, "d", "rotatePlayerRight();", "stopRotatePlayerRight();");
#2
07/12/2006 (7:37 pm)
That did the trick! Thanks. I think I initially had the brackets and semi-colons, but not the quotation marks, which must have caused the original syntax errors. Cheers! :)