Can't find the answer...
Just try set up the key (Space) button => enable (show) GUI. But i cant.
I paste code in Global script:
if (IsKeyPressed(32) == 1)
gui(3). Visible = true ;
What i do wrong ???
It should be done like this:
if (IsKeyPressed(32) == 1) {
Ã, gui[3].Visible = true;
}
I changed the () marks to []
Also, where exactly in the Global Script is it?
IsKeyPressed I think needs to be use in repeatedly_execute to work properly. You could also add to on_key_press, e.g.:
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 == 32) gui[3].Visible = true;
// Other keycode conditions (Quit, Save, Load, Inventory, etc)
}
But i can do this in global script :
if (keycode==8) gui[3].Visible = true;
Function is work...and now gui3 must disappear when "space" pressed again. Global script to allow do this?
if (keycode==8) if (gui[3].Visible) gui[3].Visible = false;
else gui[3].Visible = true;
Though this way the gui might flash on and off if you keep the key pressed, I'm too lazy to work something about this though.
EDIT: TD's problem's solved.
Yay! Now it's work! Thanks to dudes and cyborg! :)
Wait the minute!!! Some mistake there. I suppose ur was right
alkis21!!!
if (keycode==8) {
Ã, if (gui[3].Visible==true) {
Ã, Ã, gui[3].Visible=false;
Ã, Ã, return; } //"return" stops running any more functions
Ã, else {
Ã, Ã, gui[3].Visible=true;
return; }
}
This should work. :)
Does Pablo's suggestion work, TD?
Wah! Dosn't work... :(
GUI apeear when push the button but not disappear when push the button again...
...well, guess so better to set other button for disappearing GUi...
Pablo's code should work... Can you post your on_key_press code?
What key do you want to turn the GUI on/off? You originally said Space, but now you're using keycode 8, which is Backspace.
If the GUI is set to Pop up modal, on_key_press won't get called while it is open, AFAIK.
Ah, that's true. In that case, you will need to use IsKeyPressed like you originally had, and check it in repeatedly_execute_always, as this runs when Popup Modal GUIs are visible. You might also want to use a variable to stop it 'blinking' on and off if the key is held (what Gilbot said), e.g. (untested):
int KeyHeld;
function repeatedly_execute_always () {
// Make rep_ex_always if there isn't one, or paste this in if there is:
if (IsKeyPressed (8)) {
if (KeyHeld == 0) {
if (gui[3].Visible==true) {
gui[3].Visible=false;
}
else {
gui[3].Visible=true;
}
KeyHeld = 1;
}
}
else KeyHeld = 0; // Reset it when key released.
}
EDIT:
Corrected conditions. This version DOES work, honest, but Pablo's module (or at least hthe way he's modified on_key_press) might be better.
Ashen, I don't think your code would stop the blinking either.
EDIT: I just tested it and it doesn't.
Here's how I did it (I have a GUI that pops up when Space is pressed too):
int KeyHeld=0;
function repeatedly_execute_always() {
if ((KeyHeld) && IsKeyPressed(KeyHeld)) return;
KeyHeld=0;
if (IsKeyPressed(' ')) {
gui[3].Visible = (!gui[3].Visible);
KeyHeld = ' ';
}
}
I would make a new module and put a on_key_press() function inside it, without the line that blocks keypresses while the game is paused. In my opinion this would be the most non-confusing way of doing this. Actually I just made one. Just import this module into AGS from the Module Manager.
http://koti.mbnet.fi/pabsoft/ags/keypress_module.scm
There.
Seems it work, Pablo! :) (SOLVED)