Author Topic: simplest possible three-button GUI for saving/pausing/quitting/etc?  (Read 350 times)


  • Posts: 16
I've been searching for at least 3 days in the forums, the wiki, and on google for a solution to this and sadly, most of the topics in the forum for it have out-of-date code, or links to things on websites that are no longer functional, or forum posts that end with replies like "fixed it- thanks!" or "search the forum, silly!" with no other details. It's been difficult scouring for a solution, and what I'm after seems much more simple than the very complex questions I'm finding, so maybe someone can help me out:

in the default game, there's a lot of game GUIs that happen when you press the F keys or ESC or Tab, or that direct to OTHER guis. I don't want to use any of those(not even an inventory. it's mostly an exploration game) and just want one simple catch-all GUI that can be triggered by pressing, say, Space or Tab or something. It would display "save" "load last save" and "quit", and that's all. That's all I want- every tutorial and script example and question and custom module I can find all have to do with an array of saves, or naming your saves, or adding screenshots, or dealing with all these different GUIs for each of these, and the code is so complex I don't know how to delete what I don't need and use it for my purposes- I just want a single extremely simple looking one. If an array of saves is all that exists, I'd be fine it re-writes the save over and over again. A great tip I found was to just appropriate code from the default "gPanel" gui, but that's only gotten me so far. Yes, I have read the Wiki, searched the forums(most examples are from the 00s at this point), and used f1, heheh

what I have so far in the global script, is very simple code wherein if I press tab, a GUI will pop up with 3 options: to save, load previous save, or quit. My goal is to eventually also use pretty much the same gui as the title screen (without 'save', of course). Hopefully this would let players load their last save when they start the game up, and save their position in the game whenever they like by toggling this "gSaveScreen" with Tab. On game load, it's set as not visible. So then...

Code: Adventure Game Studio
  1. function on_key_press(eKeyCode 9)
  2. {
  3.    gSaveScreen.Visible = true;
  4.   if ((keycode == eKeyTab) && gSaveScreen.Visible) {
  5.     // Use tab to turn the panel off.
  6.     gSaveScreen.Visible = false;
  7.     mouse.UseDefaultGraphic();
  8.   }
  9. }
  11. function guiSaveBtn_OnClick(GUIControl *control, MouseButton button)
  12. {
  13. SaveGameSlot(48);
  14. guiGameStatus.Text("Game Saved!");
  15. gSaveScreen.Visible = false;
  16. }
  19. function guiLoadBtn_OnClick(GUIControl *control, MouseButton button)
  20. {
  21.  RestoreGameSlot(48);
  22.  guiGameStatus.Text("Game Saved!");
  23.  gSaveScreen.Visible = false;
  24.  }
  26. function guiQuitBtn_OnClick(GUIControl *control, MouseButton button)
  27. {
  28.  SaveGameSlot(48);
  29.  guiGameStatus.Text("Game Saved!");
  30.  Wait(40);
  31.  QuitGame(1);
  32.  }

Running this, I get an error with the very first line, that the keycode isn't valid, and I don't know what to do there- as far as I know, this is correct. trying on_key_press "(int 9)" doesn't work, "(eKeyCode 9)" doesn't work, "(eKeyCode eKeyTab)" doesn't work. Different examples I've searched for give all of these as workable code, so I don't know which to use.
I understand "show_save_game_dialog();" exists already, but I have no idea how to relate that to opening this GUI, or if I even need to since these three actions are all I need. And just to be sure: the save state "48" doesn't mean anything, it's just a randomly chosen number.

the sheer number of threads I've been cycling between for a while now is driving me crazy and I want to get this simple thing out of the way before I go forward any more with my game- if I can't figure out how to save or load, then it's pointless to continue isn't it? I do want to finish this, though, so thank you for helping me out. If it comes down to it I would be willing to pay for direct help with this because this is a bit of a bottleneck. Sometimes the easiest things to do are the hardest for a beginner- I can't search for the answer if I don't know what the problem is, you know?



  • Global Moderator
  • Posts: 6,750
  • Private Insultant
    • I can help with proof reading
    • I can help with translating
When you create ("declare") a function, the bit in the parenthesis (the "arguments" or "parameters") are variable names (with variable type) that you use in the function. The values of those variables are then filled in when the function is run ("called"), in the line that calls the function. You should not put the value in the function declaration, that makes no sense, just the variable name that you want to use to refer to that value inside the function.

The special built-in function on_key_press(), is called automatically by AGS when a key is pressed, and the value of the argument is the key that is pressed. So if you want the code to run when Tab is pressed, you should put:

Code: Adventure Game Studio
  1. function on_key_press(eKeyCode keycode) // "keycode" is the variable name used inside the function.
  2. {
  3.   if(keycode == eKeyTab)
  4.   {
  5.     // Use tab to turn the panel on or off.
  6.     if(gSaveScreen.Visible)
  7.     {
  8.       gSaveScreen.Visible = false;
  9.       mouse.UseDefaultGraphic();
  10.     }
  11.     else
  12.       gSaveScreen.Visible = true;
  13.   }
  14. }
« Last Edit: 11 Nov 2018, 10:27 by Snarky »


  • Posts: 16
that makes a lot of sense, thank you. This is what happens when you have to rely on wiki stuff, heh. I appreciate you explaining something that rudimentary.
I gave it a spin and it seems to work perfectly so I can appropriate the GUI for other things later on. Thanks again, hopefully this can help others too.

I didn't think getting the GUI to show would've been harder for me than the actual saving and quitting code :P
thanks again.


  • Cavefish
  • Posts: 5,013
  • Fleeing the Cylon tyrrany...
    • Cassiebsg worked on a game that was nominated for an AGS Award!
Without trying to be a "smartass" I suggest you add ESC to bring down the menu as well as Tab (I'm assuming you are not using ESC for anything else, of course).

Reason for it is that I suspect that a lot of players, like me, will press ESC automatic and if that doesn't work they will most likely assume "there's no menu"... and the go on posting about how to access the save menu. Unless you specifically tell the player that the menu can be accessed my Tab key (not on a readme.txt but in game).... then you'll probably just annoying those that instinctively press ESC before they think it's the tab key. (laugh)(roll)
There are those who believe that life here began out there...


  • Posts: 415
    • eri0o worked on a game that was nominated for an AGS Award!
@my2k, we are trying to update and have a new manual here, that would ship with a newer version of ags, could you give an example of which session the information you need you would expect to find? And could you try searching on the webpage and report if it turns useful results?