Is there anyway to let the user speedup/slow down the char in the game with some controls with code ?
SetCharacterSpeed (CHARID, speed)
SetCharacterSpeedEx (CHARID, x_speed, y_speed)
or, in the newer versions
Character.SetWalkSpeed(int x_speed, int y_speed)
What exactly do you want to do?
If you want it to be changeable by the player, you'll also need the character[CHARID].walkspeed variable, e.g.:
//on keypress
if (keycode == 372) { // 'Up' arrow
StopMoving (EGO); // Can't change speed while char is moving
SetCharacterSpeed (EGO, character[EGO].walkspeed + 1);
}
if ((keycode == 380) && (character[EGO].walkspeed > 1)) { // 'Down' arrow. Won't go lower thatn 1, since negative values cause errors, and 0 will jump straight to the mouse.
StopMoving (EGO);
SetCharacterSpeed (EGO, character[EGO].walkspeed - 1);
}
Of course, it could be done with GUI buttons or a slider, or whatever.
Thanks for helping me . I use the last code you gave but it gave me the if error .
#sectionstart on_key_press // DO NOT EDIT OR REMOVE THIS LINE
function on_key_press(int keycode) {
// called when a key is pressed. keycode holds the key's ASCII code
if (IsGamePaused() == 1) keycode=0; // game paused, so don't react to keypresses
if (keycode==17) QuitGame(1); // Ctrl-Q
if (keycode==363 && GetCursorMode() != 7) Save(); // F5
if (keycode==365) Load(); // F7
if (keycode==367) RestartGame(); // F9
if (keycode==434) SaveScreenShot("scrnshot.bmp"); // F12
if (keycode==9 && GetCursorMode() != 7) show_inventory_window(); // Tab, show inventory
if (keycode==19) Debug(0,0); // Ctrl-S, give all inventory
if (keycode==22) Debug(1,0); // Ctrl-V, version
if (keycode==1) Debug(2,0); // Ctrl-A, show walkable areas
if (keycode==24) Debug(3,0); // Ctrl-X, teleport to room
}
if (keycode == 372) { // 'Up' arrow
StopMoving (EGO); // Can't change speed while char is moving
SetCharacterSpeed (EGO, character[EGO].walkspeed + 1);
}
if ((keycode == 380) && (character[EGO].walkspeed > 1)) { // 'Down' arrow. Won't go lower thatn 1, since negative values cause errors, and 0 will jump straight to the mouse.
StopMoving (EGO);
SetCharacterSpeed (EGO, character[EGO].walkspeed - 1);
}
---------------------------
Compile Error
---------------------------
There was an error compiling your script. The problem was in 'Global script':
Error (line 76): Parse error: unexpected 'if'
Do you want to fix the script now? (Your game has not been saved).
---------------------------
Yes No
I think you've got an extra brace after if (keycode == 24)..., putting the new code outside the on_key_press script:
#sectionstart on_key_pressÃ, // DO NOT EDIT OR REMOVE THIS LINE
function on_key_press(int keycode) {
Ã, // called when a key is pressed. keycode holds the key's ASCII code
Ã, if (IsGamePaused() == 1) keycode=0;Ã, // game paused, so don't react to keypresses
Ã, if (keycode==17)Ã, QuitGame(1);Ã, Ã, // Ctrl-Q
Ã, if (keycode==363 && GetCursorMode() != 7) Save();Ã, Ã, // F5
Ã, if (keycode==365) Load();Ã, // F7
Ã, if (keycode==367) RestartGame();Ã, // F9
Ã, if (keycode==434) SaveScreenShot("scrnshot.bmp");Ã, // F12
Ã, if (keycode==9 && GetCursorMode() != 7) show_inventory_window();Ã, // Tab, show inventory
Ã, if (keycode==19)Ã, Debug(0,0);Ã, // Ctrl-S, give all inventory
Ã, if (keycode==22)Ã, Debug(1,0);Ã, // Ctrl-V, version
Ã, if (keycode==1)Ã, Ã, Debug(2,0);Ã, // Ctrl-A, show walkable areas
Ã, if (keycode==24)Ã, Debug(3,0);Ã, // Ctrl-X, teleport to room
} // <-- REMOVE THIS BRACE
if (keycode == 372) { // 'Up' arrow
Ã, StopMoving (EGO); // Can't change speed while char is moving
Ã, SetCharacterSpeed (EGO, character[EGO].walkspeed + 1);
}
if ((keycode == 380) && (character[EGO].walkspeed > 1)) { // 'Down' arrow. Won't go lower thatn 1, since negative values cause errors, and 0 will jump straight to the mouse.
Ã, StopMoving (EGO);
Ã, SetCharacterSpeed (EGO, character[EGO].walkspeed - 1);
}
Removed that and got this error ?
---------------------------
Compile Error
---------------------------
There was an error compiling your script. The problem was in 'Global script':
Error (line 88): Nested functions not supported (you may have forgotten a closing brace)
Do you want to fix the script now? (Your game has not been saved).
---------------------------
Yes No
---------------------------
OK, so //<-- REMOVE THIS BRACE should be //<-- THIS BRACE SHOULD BE AT THE VERY BOTTOM
Add an '}' at the end of the script,:
SetCharacterSpeed (EGO, character[EGO].walkspeed - 1);
}
} //<-- HERE
Then check it with the match brace function (Ctrl-B), just to be safe.
This is the code I have now .
function on_key_press(int keycode) {
// called when a key is pressed. keycode holds the key's ASCII code
if (IsGamePaused() == 1) keycode=0; // game paused, so don't react to keypresses
if (keycode==17) QuitGame(1); // Ctrl-Q
if (keycode==363 && GetCursorMode() != 7) Save(); // F5
if (keycode==365) Load(); // F7
if (keycode==367) RestartGame(); // F9
if (keycode==434) SaveScreenShot("scrnshot.bmp"); // F12
if (keycode==9 && GetCursorMode() != 7) show_inventory_window(); // Tab, show inventory
if (keycode==19) Debug(0,0); // Ctrl-S, give all inventory
if (keycode==22) Debug(1,0); // Ctrl-V, version
if (keycode==1) Debug(2,0); // Ctrl-A, show walkable areas
if (keycode==24) Debug(3,0); // Ctrl-X, teleport to room
}
if (keycode == 372) { // 'Up' arrow
StopMoving (MIKE); // Can't change speed while char is moving
SetCharacterSpeed (MIKE, character[MIKE].walkspeed + 1);
}
if ((keycode == 380) && (character[MIKE].walkspeed > 1)) { // 'Down' arrow. Won't go lower thatn 1, since negative values cause errors, and 0 will jump straight to the mouse.
StopMoving (MIKE);
SetCharacterSpeed (MIKE, character[MIKE].walkspeed - 1);
}
}
Error
---------------------------
Compile Error
---------------------------
There was an error compiling your script. The problem was in 'Global script':
Error (line 77): Parse error: unexpected 'if'
Do you want to fix the script now? (Your game has not been saved).
---------------------------
Yes No
---------------------------
The first brace, the one after if (keycode==24)..., is back in there, AS WELL as the final one. Code should be:
function on_key_press(int keycode) { // Start of on_key_press
// called when a key is pressed. keycode holds the key's ASCII code
if (IsGamePaused() == 1) keycode=0; // game paused, so don't react to keypresses
if (keycode==17) QuitGame(1); // Ctrl-Q
if (keycode==363 && GetCursorMode() != 7) Save(); // F5
if (keycode==365) Load(); // F7
if (keycode==367) RestartGame(); // F9
if (keycode==434) SaveScreenShot("scrnshot.bmp"); // F12
if (keycode==9 && GetCursorMode() != 7) show_inventory_window(); // Tab, show inventory
if (keycode==19) Debug(0,0); // Ctrl-S, give all inventory
if (keycode==22) Debug(1,0); // Ctrl-V, version
if (keycode==1) Debug(2,0); // Ctrl-A, show walkable areas
if (keycode==24) Debug(3,0); // Ctrl-X, teleport to room
if (keycode == 372) { // Start of 'Up' arrow code
StopMoving (MIKE); // Can't change speed while char is moving
SetCharacterSpeed (MIKE, character[MIKE].walkspeed + 1);
}// End of 'Up' arrow code
if ((keycode == 380) && (character[MIKE].walkspeed > 1)) { //Start of 'Down' arrow code.
StopMoving (MIKE);
SetCharacterSpeed (MIKE, character[MIKE].walkspeed - 1);
} // End of 'Down' arrow code
} //End of on_key_press
Sorry didn't see that Ashen ,, thanks for all the help .. your the man when it comes to this code ..
Candle: You've given me the idea of "translating" these error messages. Sometimes the messages that the AGS Editor gives are not always apparent and might even be a bit cryptic. At least in the future you will always be able to reference it. :)