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:
//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"
You have to define functions before you call them. Just move walkUp() above on_key_press().
QuoteYou have to define functions before you call them. Just move walkUp() above on_key_press().
Thanks! I'll remember this for the future