Scripting questions, discussions, etc

Steve_Yorkshire
Posts: 257
Joined: Tue Feb 03, 2015 10:30 pm

Okeedokee, here's a funny little thing I found. If you exit a level whilst still having the gamepad stick in movement, the input locks and is remembered when you start a new mission the movement input restarts.

How to test in default Torque:
2) Load a mission and start moving.
3) Keep pressure on the thumbstick and exit using the Back button on gamepad, or Esc/select quit/yes with mouse (keep that thumbstick in move position)
5) Start new mission
6) See player start moving from leftover input

Solution:

in scripts/client/default.bind.cs, add this new function (anywhere is fine)
//to stop movement being left over, after death or end of mission
{
$mvYawLeftSpeed = 0;$mvYawRightSpeed = 0;
$mvPitchUpSpeed = 0;$mvPitchDownSpeed = 0;

$mvRightAction = 0;$mvLeftAction = 0;
$mvForwardAction = 0;$mvBackwardAction = 0;
}
In scripts/server/gameCore.cs, add this at the bottom of onMissionEnded
function GameCore::onMissionEnded(%game)
{
//echo (%game @"\c4 -> "@ %game.class @" -> GameCore::onMissionEnded");

// Called by endMission(), right before the mission is destroyed

// Normally the game should be ended first before the next
// mission is loaded, this is here in case loadMission has been
// called directly.  The mission will be ended if the server
// is destroyed, so we only need to cleanup here.

physicsStopSimulation("server");
%game.endGame();

cancel($Game::Schedule);$Game::Running = false;
\$Game::Cycling = false;

//new from here
echo("c\4End any left over gamepad input");
}
You could probably also include a var to see if there is a gamepad connected or even cycle through gamepad inputs to see if any are still active, but this works fine.

#### Re: Stop Left-Over Gamepad Input

JeffR
Steering Committee
Posts: 840
Joined: Tue Feb 03, 2015 9:49 pm