simplest possible three-button GUI for saving/pausing/quitting/etc?

Started by my2k, Sun 11/11/2018 10:05:35

Previous topic - Next topic

my2k

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: ags

function on_key_press(eKeyCode 9) 
{
   gSaveScreen.Visible = true; 
  if ((keycode == eKeyTab) && gSaveScreen.Visible) {
    // Use tab to turn the panel off.
    gSaveScreen.Visible = false; 
    mouse.UseDefaultGraphic();
  }
}

function guiSaveBtn_OnClick(GUIControl *control, MouseButton button)
{
SaveGameSlot(48);
guiGameStatus.Text("Game Saved!");
gSaveScreen.Visible = false;
}


function guiLoadBtn_OnClick(GUIControl *control, MouseButton button)
{
 RestoreGameSlot(48);
 guiGameStatus.Text("Game Saved!");
 gSaveScreen.Visible = false;
 }

function guiQuitBtn_OnClick(GUIControl *control, MouseButton button)
{
 SaveGameSlot(48);
 guiGameStatus.Text("Game Saved!");
 Wait(40);
 QuitGame(1);
 }



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?

Thanks.

Snarky

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: ags

function on_key_press(eKeyCode keycode) // "keycode" is the variable name used inside the function. 
{
  if(keycode == eKeyTab)
  {
    // Use tab to turn the panel on or off.
    if(gSaveScreen.Visible)
    {
      gSaveScreen.Visible = false; 
      mouse.UseDefaultGraphic();
    }
    else
      gSaveScreen.Visible = true; 
  }
}

my2k

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.

Cassiebsg

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...

eri0o

@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?

SMF spam blocked by CleanTalk