In essence what I want to do is this: press Esc to open the pause menu, and then press Esc again to close it.
I have achieved this by using the following if-statement in the repeatedly_execute() function (if there is a better way please tell me):
if(IsKeyPressed(eKeyEscape)){
gPauseMenu.Visible = !gPauseMenu.Visible;
}
Of course, the issue here is that the function executes several times.
I've tinkered a (very) small amount with C before (in the context of microcontrollers), and how I would've solved similar situations is by adding a while-loop:
if(IsKeyPressed(eKeyEscape)){
gPauseMenu.Visible = !gPauseMenu.Visible;
while(IsKeyPressed(eKeyEscape)){}
}
This way we would only move on when the user has released the key.
Sadly, this doesn't work in AGS because the game closes after some number of loops.
A hack solution would be to use Wait() in order to make the number of loops stack slower:
while(IsKeyPressed(eKeyEscape)){
Wait(1);
}
This way, you'd need to hold down Escape for about an hour for the game to close.
However, calling Wait() makes the mouse cursor disappear for the duration waited, and that is freaking ugly.
So my question is this: can you comfortably wait until a keyboard key is released?
also if it turns out I just missed a better function that does exactly what I want I will be very upset
I put mine in the on_key_press function that comes predefined in the global script:
function on_key_press(eKeyCode keycode)
{
if (IsGamePaused()) {
if (gQuitGui.Visible && keycode == eKeyEscape) { //close quit GUI with Esc key
gQuitGui.Visible = false;
return;
}
else keycode = 0; // any other key is ignored if the game is paused
}
if (keycode == eKeyEscape) gQuitGui.Visible = true; // the gui is set to pause the game when visible
}
I'm sure there's a more elegant / optimal way to do it, but this works!
Quote from: Laura Hunt on Wed 18/03/2020 18:41:53
I put mine in the on_key_press function that comes predefined in the global script
Yeah I just realized you could do that! You're right, it ain't pretty, but at least it does the job.
Of course the gui still flickers if you hold down the key, but I guess you can't have everything
To avoid the blinking you could try this:
you declare an int in Global Variables or at the top in the script body:
int timer;
In the on key function you write:
function on_key_press(eKeyCode keycode)
{
if(keycode==eKeyA&imer<1)
{
gInventory.Visible = !gInventory.Visible;
timer ;//(I'm not sure if it's being displayed correctly but I wrote "timerPLUSPLUS;" Sometimes the plus symbols are not displayed
}
}
Then in repeatedly execute always:
if(IsKeyPressed(eKeyA)==false)timer=0;
Unless you have a lagging game, normally this should not blink anymore.
This thread about the same problem may be of help:
https://www.adventuregamestudio.co.uk/forums/index.php?topic=57704
Quote from: Matti on Thu 19/03/2020 09:20:37
This thread about the same problem may be of help:
https://www.adventuregamestudio.co.uk/forums/index.php?topic=57704
Ok yeah that did it