Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: DreadBeard on Thu 18/08/2011 20:35:28

Title: Inventory toggle, "gPanel" style.
Post by: 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.

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:


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.
Title: Re: Inventory toggle, "gPanel" style.
Post by: Khris on Thu 18/08/2011 20:54:37
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?
Title: Re: Inventory toggle, "gPanel" style.
Post by: Atelier on Thu 18/08/2011 21:09:40
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:


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


This will toggle it without the need to check whether it's already visible or not.
Title: Re: Inventory toggle, "gPanel" style.
Post by: Khris on Fri 19/08/2011 00:04:55
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.
Title: Re: Inventory toggle, "gPanel" style.
Post by: DreadBeard on Fri 19/08/2011 04:58:31
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.