Game Development Community

RC2: xaxis + yaxis causes crash for joystick command

by Leroy Frederick · in Torque Game Builder · 06/09/2006 (2:03 pm) · 2 replies

As the topic tile says, when xaxis + yaxis is active, a crash occurs (buttons are fine though)

sample code:
$enableDirectInput = "1"; activateDirectInput();
moveMap.bindCmd(joystick, "yaxis", "playerUp();", "playerUpStop();");
moveMap.bindCmd(joystick, "yaxis", "playerDown();", "playerDownStop();");
moveMap.bindCmd(joystick, "xaxis", "playerLeft();", "playerLeftStop();");
moveMap.bindCmd(joystick, "xaxis", "playerRight();", "playerRightStop();");

I may have the above code wrong hence the crashing, if this is the case, please feel free to enlighten myself and any1 who cares to know...

#1
06/09/2006 (2:41 pm)
Yes, this is an incorrect usage...

You need to do something more along the lines of:
moveMap.bind(joystick0, "xaxis", joyXaxisFunction);

function joyXaxisFunction(%val)
{
  if(%val > 0)
    playerRight();
  else
    playerLeft();
}

There is information on that in the documentation folder that comes with TGB. It's the input documentation.

Note that this does not seem to work currently for the mouse, though I have not tried it with a joystick.
#2
06/09/2006 (3:01 pm)
Thanks for the info/correction J. Alan, i'll take a look

this works without crash though, main difference being 'bind' instead of 'bindCmd' :)

$enableDirectInput = "1"; activateDirectInput();
moveMap.bind(joystick, "yaxis", playerUpDown);
moveMap.bind(joystick, "xaxis", playerLeftRight);

EDIT: Doh, the solution i discovered above is the same as J. Alan's example, I only just noticed, sorry, still a little tired :S

Does this mean the first example is not a bug? (and thus this post should be deleted)