GUI, Inventory & Menu

From Adventure Game Studio | Wiki
Revision as of 14:22, 6 August 2007 by *>Ashen
Jump to navigationJump to search

Getting rid of that big gray status bar at the top

When I test my game, there is this gray box at the very top of the screen that I can't get rid of. I don't want it there. What is it, and how do I get rid of it?

That gray bar at the top of the screen is meant to be a status bar for your game. Not everybody will use it, and you can disable it. In the AGS Editor, simply go to the "GUIs" pane and select the "STATUSLINE" GUI, which is also #0, up at the top of the list. A toolbar window will pop up with the title “GUI 0 (0 objects)”. You will see that the value for "Visible" is set to "Normal". Change this to "Popup modal"; this way, it will only appear when called by a script. And if you never call it up, it will never appear. So don't call it up (if you don't need it)! :P

Using one inventory item on another

How do I use one inventory item on another? I couldn't find this in the manual!

Well, you just didn't look hard enough. Look under Manual Contents -> Reference -> Interaction events -> Inventory item interactions. When in the context of the interaction editor, select the "Use inventory on inv" choice. Add a "Conditional - if inventory item was used" option to determine which item was used. This event allows the player to combine items, and so on. For example, if the player had picked up a laptop computer and a battery separately, then you could use this to allow him/her to insert the battery into the computer. It is also suggested that you do it both ways; that is, if you set actions to occur when player uses item A on item B, then also set actions for if the player uses item B on item A as well.

GUI buttons not working

The buttons on my GUI doesn't work! I'm pretty sure the script is all set, but it still won't run it. Why?

First off, make sure you have the GUI number right, and that you have an if statement to cover the event when interface== your GUI number. For example, if you're using GUI #5, make sure there's an else if (interface==5) line in there, with braces if needed. Second, make sure you're checcking the right button numbers. Next, check each button to see if its action is set to "Run Script". This is most commonly the problem.

New in AGS V2.7 and above enables you to create separate functions for different buttons clicked, consult the manual for more info.

Adding money to your game

How can I add money into my game? You know, like the character carries around an inventory item that is a coin, and it keeps count of how much money he know what I mean...! And what about having multiple inventory items! HUH!?

Easy. The character's global inventory variables (such as player.inv[34], or player.InventoryQuantity[iMoney.ID] for V2.7 and newer) are integers and can be used to keep track of how many items (or, in this case, money) the character has.

Adding score/hotspot info to the big grey status bar

I've decided to use AGS's built-in STATUSLINE GUI in order to have a status bar at the very top of my screen, with some information. How do I add a score display, or the name of a hotspot?

The answer to this question is indeed in the AGS manual (help file — "ags.chm"), under "Editing the GUIs". Here is an excerpt from the manual:

Interface text

You can easily display static text on interfaces. For example, the Sierra-style interface displays the score in the status bar.
To add text to a GUI, you add a label. Click the "Add label" button, then drag out a rectangle like you did when adding a button. You can change the text displayed in the label by editing the "Text" property. Notice that the text automatically wraps around to fit inside the rectangle you drew.
As well as typing normal text into the label, you can add some special markers which allow the text to change during the game. The following tokens will be replaced with the relevant values in the game:

  • @GAMENAME@ The game's name, specified on the Game Settings pane
  • @OVERHOTSPOT@ Name of the hotspot which the cursor is over
  • @SCORE@ The player's current score (number only)
  • @SCORETEXT@ The text "Score: X of Y" with the relevant numbers filled in.
  • @TOTALSCORE@ The maximum possible score, specified on the Game Settings pane

Example: You have @SCORE@ out of @TOTALSCORE@ possible points.

The Properties window also allows you to align the text to the left, right, or centre, as well as change its font and colour.

It may also be helpful to use the Description Module.

Using a specific inventory item to trigger an action

I need a specific inventory item to trigger an action when interacting it with a hotspot/object/character/other item. So far, I can only see how to set it so that any item can be used.

If you're using the Interaction Editor, choose "Conditional - if inventory item is used" action under the "Use inventory item on (whatever)" interaction.

Otherwise, if you're using scripting only, use the following code (in AGS V2.62):

 if (player.activeinv == 31) {
   // Place code here

This will detect whether the player's current inventory item selected is #31, and if so, the code between the braces is run. Take out the // comments if you want.

In AGS V2.7 and higher, use the following code:

 if (player.ActiveInventory==iItem){
   // Place code here

This will detect whether the player's current inventory item selected is iItem. Rather than using the item numbers, AGS now uses script O-Names: usually i followed by the item name for inventory items(so, if the item is called Key the script O-Name will be iKey), which are shown on the 'Inventory Items' window of the editor).

Customizing graphics of AGS default GUIs; Creating your own GUIs

Can I customize the graphics of the default inventory GUI? Can I create my own?

Of course you can. Make sure AGS is actually usng the inventory GUI. You need to check the functon show_inventory_window section of the global script; otherwise, it uses the internal inventory GUI that you cannot edit. Make sure the function reads as such:

 function show_inventory_window () {
   // switch to the Use cursor (to select items with)
   SetCursorMode (MODE_USE);
   // But, override the appearance to look like the arrow
   SetMouseCursor (6);

Or, for AGS V2.7 and above:

 function show_inventory_window () {
   gInventory.Visible = true;
   // switch to the Use cursor (to select items with)
   mouse.Mode = eModeUse;
   // But, override the appearance to look like the arrow
   mouse.UseModeGraphic (eModePointer);

Interacting with inventory

How come interacting with an inventory item in my custom inventory GUI doesn't do anything except select the item? The LOOK mode works just fine.

You can't interact with an item the way you'd expect, as in doing something to the object. The INTERACT mode is reserved for selecting the item. Instead, use the TALK mode. You can still have a button with a hand icon or some such graphic displayed, but make it set the cursor mode to TALK instead, and use the TALK interaction in the interaction editor.

Creating your own custom inventory

How would I go about creating my own custom inventory GUI? I don't much like the default AGS one. OR, I have a problem creating my own inventory GUI. HELP!

Everything you need to know about custom inventory GUIs can be found in this thread.

Inventory items don't show up

The inventory items won't display if the InvWindow GUI control is smaller than an inventory item slot (40x22 pixels by default). Enlarge the InvWindow control or decrease its ItemWidth and ItemHeight properties in the GUI editor.

Getting that classical Sierra look for GUIs

How can I make the classic Sierra GUI, with the white menu bar with the "file" icon popup window where the player can save his game, quit, control the volume, etc.?

This article/section was written for an older version of AGS.
AGS 2.7 uses new, easier, Object-Oriented scripting and so this article needs updating to reflect the new style scripts.

Ah yes, the good ol' Sierra control panel GUI. This is an easy one, but surely you should look through the manual first before asking such a question. The typical Sierra control panel uses the following controls:

  • New Game button
  • Save Game button
  • Load Game button
  • Quit Game button
  • Play Game button
  • Help button
  • About Us button
  • Volume Control slider
  • Speed Control slider
  • Quality Control slider

The New Game button would call the RestartGame() command. The Save Game button would either call up the SaveGameDalog() command or utilize your own custom Save dialog (this is advanced and requires scripting knowledge; I will make a tutorial eventually on this). The Load Game button would either call the RestoreGameDialog() command, or utilize your own custom Load dialog (again, this is advanced and a tutorial for both Save and Load will be made eventually). The Quit Game button would simply call the QuitGame() command. Please look it up in the manual for more help. And the Play Game button would simply exit the Control Panel GUI and return control to the game, so it would simply call the GUIOff() command.

As for the sliders, you will have to research more on Slider GUI objects and the scripting events and code, such as SetSoundVolume(), SetMusicVolume(), SetSpeechVolume() (if controlling separate volumes), SetDigitalMasterVolume() (if controlling one master volume), and SetGameSpeed(). Look all of these up in the AGS manual.

As for Quality Control, I never had any idea what it actually did in the classic Sierra games. I never noticed any difference, so I never bothered with it and always set it all the way up. I think it may have had something to do with the character's walking speed compared to game speed... I have no idea. I wouldn't bother with it.

You may also find sample AGS templates at this web site here. Put the .AGT files in your AGS editor main directory and start a New Game to use these templates.

Having a semi-transparent GUI in your game

Is it possible to have an inventory GUI (or any type of GUI) with a semi-transparent background? If so, what if I wanted to have the objects (or only certain ones) inside the GUI non-transparent?

Simple! Well, okay, maybe not really simple, but simple enough that anybody can do it. Now this all depends on whether your game is true-colour or hi-colour (256-colour games cannot do this).

If you have a hi-colour game, you will have to use two GUIs, one on top of the other. The bottom GUI will consist of everything that you want to appear semi-transparent. Then use the SetGUTransparency() function to make the entire GUI transparent. (See why we need two of them now?) On the top GUI, put everything that is NOT transparent, and set that GUI's background to 0 (fully transparent, no color). Make sure that both GUIs are in the same exact location and that you created the GUI that goes behind first.

If you are running a true-colour game, it is much easier. Simply edit your background image (if you need a simple colour, you'll still need an imported sprite) and change its transparency to whatever you need (it might be called "opacity" in certain programs, which is just the opposite of transparency). You must save the image as a .PNG file, which is the only file format with alpha-blended transparencies that AGS supports (as far as I know).

If you have any questions about making an entire image semi-transparent using alpha channels, please do not ask in the Beginners' Tech Forum. Instead, ask in the General Discussion Forum.

Removing or changing the default blue border around GUIs

I hate that ugly blue border around the default GUIs in AGS. How do I change it, or get rid of it altogether?

First off, that setting is deceptively named "Foreground colour" in the AGS Editor, under GUI Properties. Also remember that AGS treats Color #0 (zero) as transparent, so set the GUI's Foreground Color to "0" to get rid of it, or a different pallette color number to change it.

NOTE: As of AGS V2.7, this setting has been renamed "Border Color".

Making your GUI modal

How do I make it so that when I pull up a certain GUI no other buttons or GUIs can be interacted with? I want my GUI to have exclusive attention and never EVER be ignored. :)

First off, you want to make sure your game is paused when that GUI is called. Make its Visible property "Popup modal". Next, wherever your code to turn on that GUI goes, also make sure to set all other visible GUIs to be unclickable, like so:

 SetGUIClickable(GUI1, 0);
 SetGUIClickable(GUI2, 0);

Or, for AGS V2.7 and above:

 gBlah.Clickable = false;
 gHaha.Clickable = false;

Et cetera, et cetera. When you close your GUI, restore all the other GUI's clickable properties by using the same code above, except passing "1" (or "true") as a parameter instead of "0" (or "false").

Changing AGS's default speech/narrator dialog boxes to your own

How would I change AGS's default black-and-white dialog boxes into something more colourful? I want to customize the narrator/speech GUIs!

This is found in the AGS manual, albeit a bit hidden:

Customized Text Windows

If you want to add a personal touch to the standard white text-boxes which display all the messages during the game, you can create a border using the GUI Editor.
Create a new GUI, and check the "text window" box for it. The element will be resized to about 1/4 of the screen, and you will see 8 pictures - one in each corner and one on each side. These are the border graphics. You change the graphic for a corner in the normal way.
In the game, the corner graphics will be placed in the respective corners of the text window, and the side graphics will be repeated along the edge of the window. To tell the game to use your custom text window style, go to the General Settings pane, and check the "Text windows use GUI" box. Then, enter the number of the GUI which you used.
You can also set a background picture for the text window. In the GUI editor, simply set a background picture for the GUI element. The graphic you specify will not be tiled or stretched in the game; however, it will be clipped to fit the window. You should use a graphic of at least about 250x80 pixels to make sure that it fills up the whole window.
To set the text colour in the window, simply set the Foreground Colour of the GUI and that will be used to print the message text in.

"Error: InventoryScreen: one or more of the inventory screen graphics have been deleted"

Every time I try to open my Inventory GUI I get this error. What's going on here?

This is most likely to happen if you've started a game using the 'Empty' template. This starts a game with NO existing sprites - which includes the ones needed by the default Inventory GUI. You'll need to import three sprites to be used for the 'Look at', 'Use' and 'OK' buttons. Then, right-click them, select 'Change sprite number ...' and renumber them to 2041, 2042 and 2043 respectively.

Checking if the player has a certain Inventory Item

I want an interaction to happen only when the player has an Inventory Item (like a key to open a door) OR something not to happen when the player has an Item. How do I do that?

Simply use the InventoryQuantity property, e.g.:

 if (player.InventoryQuantity[iKey.ID] == 0) Display("You don't have the key.");


 if (player.InventoryQuantity[iStolen.ID] != 0) Display("You can't go in there carrying Stolen goods.");

If you want to stop the player from taking an Item multiple times (like taking someting out of a drawer), you're better using a variable. If you use InventoryQuantity and the player can lose the Item later in the game, they'll be able to go back and pick it up again.


  • The InventoryQuantity property was introduced in V2.7. Before that, use teh character[].inv array.