I'm trying to open a GUI with the "n" button. Once the GUI is open, I want to be able to close the GUI with the "n" button again. However, if I try to do something like this:
if ((IsKeyPressed(eKeyN)) &&
(!GUIOpen))
{
gNotebook.Visible=true;
GUIOpen=true;
}
else if (GUIOpen)
{
gNotebook.Visible=false;
GUIOpen=false;
}
}
it doesn't work. How do I fix this and where do I put the code?
I've just realised something else I could try:
if ((NotebookOpen) &&
(IsKeyPressed(eKeyN)))
{
gNotebook.Visible=false;
NotebookOpen=false;
}
if ((!NotebookOpen) &&
(IsKeyPressed(eKeyN)))
{
gNotebook.Visible=true;
NotebookOpen=true;
}
However, the GUI won't close when "n" is pressed. The GUI pauses game when shown. Any help?
Normally this should work:
function on_key_press(eKeyCode key)
{
if (key == eKeyN)
{
gNotebook.Visible = !gNotebook.Visible; // switch GUI visibility to reverse of what it is now
}
}
You can put this in GlobalScript.asc. If the script already contains function "on_key_press", then just add this new code into it.
Regarding your original code, you do not need to have separate NotebookOpen variable, because gNotebook.Visible already tells you if GUI is visible (remember, you can both set and get its value).
It still doesn't work. When the GUI is open, the key doesn't seem to register.
Quote from: TDBFW1 on Sat 23/09/2017 19:59:00
It still doesn't work. When the GUI is open, the key doesn't seem to register.
Do you have any TextBoxes on the GUI? I think they catch all the key input.
Other than that, I cannot think of anything but maybe another script module overrides keypresses when it's open, if you have any.
No textboxes or modules. I don't know what's wrong...
So If I change the GUI to normal, initially off it works. No idea why it doesn't work when paused. Thanks anyway
Quote from: TDBFW1 on Sat 23/09/2017 21:01:29
So If I change the GUI to normal, initially off it works. No idea why it doesn't work when paused.
Does your on_key_press function has something like this:
if (IsGamePaused())
return;
?