Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: hezza on Sun 28/07/2013 11:44:00

Title: WASD movement problems
Post by: hezza on Sun 28/07/2013 11:44:00
I recently found the Keyboard Movement Module (which I will be using from now on), however I wanted to know why the test code for WASD movement didn't work.
Just curious really, so that I don't make a similar mistake in the future:

Code (AGS) Select

//main global script file

function on_key_press(eKeyCode keycode)
{
  if (IsGamePaused()) keycode = 0; // game paused, so don't react to keypresses
 
  if (keycode == eKeyCtrlQ) QuitGame(1); // Ctrl-Q
  if (keycode == eKeyF9) RestartGame(); // F9
  if (keycode == eKeyF12) SaveScreenShot("scrnshot.pcx");  // F12
  if (keycode == eKeyCtrlS) Debug(0,0); // Ctrl-S, give all inventory
  if (keycode == eKeyCtrlV) Debug(1,0); // Ctrl-V, version
  if (keycode == eKeyCtrlA) Debug(2,0); // Ctrl-A, show walkable areas
  if (keycode == eKeyCtrlX) Debug(3,0); // Ctrl-X, teleport to room
  if (keycode == eKeyW) walkUp();
}

  function walkUp()
{
   
    cCharacter.Walk(cCharacter.y + 20,  cCharacter.x,  eNoBlock,  eWalkableAreas);
}



The error I get is: "Error (line 30): Undefined token "walkUp"
Title: Re: WASD movement problems
Post by: Khris on Sun 28/07/2013 11:46:13
You have to define functions before you call them. Just move walkUp() above on_key_press().
Title: Re: WASD movement problems
Post by: hezza on Sun 28/07/2013 11:56:34
QuoteYou have to define functions before you call them. Just move walkUp() above on_key_press().

Thanks! I'll remember this for the future