Inventory toggle, "gPanel" style.

Started by DreadBeard, Thu 18/08/2011 20:35:28

Previous topic - Next topic

DreadBeard

I did a search but only got errors, no matter what I searched. It might be broken.

As I learn AGS and modify the default game in to my own; I have been attempting to make the Inventory window toggle with a second press of a button (default, TAB) the way the "gPanel" shows up and goes away when you press escape.

I tried to mimick the code I saw used for the gPanel, but it just doesn't go away when I press again. Here's an example:

Code: ags

 if ((keycode == eKeyTab) && (gInventory.Visible))
  {
    gInventory.Visible= false;
    return;
  }



There were other IconBar.Visible and such but seemed to make no difference anyway.

I hope someone can help, thanks for reading.

Khris

The code is alright, I think you have to move it further up inside the function though.

About one screen down from the start of on_key_press, AGS exits the function if the game is paused, so any key press handling below that is ignored in that case.
Since the inventory GUI is by default set to pause the game while it's visible, the code you inserted isn't executed.

Quote from: DreadBeard on Thu 18/08/2011 20:35:28
I did a search but only got errors, no matter what I searched. It might be broken.
What do you mean by that? The forum search? What errors did you get?

Atelier

Quote from: Khris on Thu 18/08/2011 20:54:37
Quote from: DreadBeard on Thu 18/08/2011 20:35:28
I did a search but only got errors, no matter what I searched. It might be broken.
What do you mean by that? The forum search? What errors did you get?

The forum search has been down a couple of days now :-\

Alternatively if you like, you could do this:

Code: ags

 if (keycode == eKeyTab) gInventory.Visible = !gInventory.Visible;


This will toggle it without the need to check whether it's already visible or not.

Khris

While that's true, the problem is that it's better to separate turning the GUI on and off here.
Pressing tab shouldn't display the inventory if the game is paused or the Panel is showing so turning the inventory GUI on should be handled below the "pause -> exit" line.
Turning it back off on the other hand must be above that to avoid the original problem.

DreadBeard

#4
This is what I got:
QuoteDatabase Error
Please try again. If you come back to this error screen, report the error to an administrator.

I only used keyword 'inventory'...

--Edit
Also, that worked. Thanks for the advice. It seems such an obvious solution now. I dunno if this should be moved to beginner questions.

SMF spam blocked by CleanTalk