Adventure Game Studio

AGS Support => Modules, Plugins & Tools => Topic started by: Darth Mandarb on Tue 13/01/2004 04:26:23

Title: Custom Inventory GUI
Post by: Darth Mandarb on Tue 13/01/2004 04:26:23
I have scoured the AGS help file ...

I have searched the forums ...

I have read through countless tutorial pages ...

I have searched the knowledge base ...


I can't find anything about making Sierra style Custom Inventory GUIs!

And I thought, "There must be others, besides myself, who would find this information useful right?"

I am interested to know how AGS handles inventory and how to interact with it.  I can find little bits and pieces about this from various sources, but nothing that helps me piece it all together.

(http://www.twin-design.com/random/inv_gui.gif)
This is my inventory window.  The inventory will display, but can't be interacted (selected or ?) with.

So here's my question(s) about Inventory:
- How does AGS handle inventory items? (meaning how do I refer to inventory while scripting)
- How do you script interactions with the displayed items?
- How do you make scrolling?

I thought it would be a good idea for others, if they have Inventory questions, to add them to this thread and we can build a vault of helpful information about making Custom Inventory GUIs!

So ... I humbly call upon the Gods of AGS scripting to throw down some lightning bolts of Inventory wisdom upon this thread :)




Disclaimer :: If I missed something obvious (threads,
Help file info, FAQ, or anything) please slap me with
a moist trout!  I really did a thorough search ... I swear!!
Title: Re:Custom Inventory GUI
Post by: Timosity on Tue 13/01/2004 07:11:54
The one I made for my game is a fairly simple one where I'm able to have any interactions with items and scroll up and down.

This is the script for the inventory:

where
gui/interface 0 is the inventory gui
object 0 is the inventory window
button 1 = look
button 2 = use
button 3 = ok
button 4 = up arrow
button 5 = down arrow
-----------------------------------------------------

if (interface == 0) {

if (button == 1) SetCursorMode (1);
if (button == 2) SetCursorMode (2);

if (button == 3) {
GUIOff(0);
GUIOn(1); //this just turns back on my top menu
SetDefaultCursor();
}

if (button == 4) {
if (game.top_inv_item > 0) game.top_inv_item = game.top_inv_item-game.items_per_line;
}

if (button == 5) {
if (game.top_inv_item < game.num_inv_items-game.num_inv_displayed)
game.top_inv_item = game.top_inv_item+game.items_per_line;
}
}
---------------------------------------------------------------------------------
This is the gui in the editor:
(http://www.2dadventure.com/ags/inv.gif)

This is the gui with items that are scrollable, it only is possible to scroll when you have more items than fit in the window
(http://www.2dadventure.com/ags/inv2.gif)

you can also set the inventory dimensions with

SetInvDimensions(30,40);

in the global game start


I'm not sure if this will help for what you want but it's a simple gui that works perfectly.

But I recommend RickJ's Blue Gui which you can find in here somewhere http://www.gaia-spa.com/blusoft/
Title: Re:Custom Inventory GUI
Post by: Dorcan on Tue 13/01/2004 09:02:45
Timosity's explanations are good, but in this case the "use" button is for selecting the object, so if someday you'll need the "interact button" in your inventory, you can find my tutorial here

http://www.digitalmindstudio.ch/script.php?id=4&langue=en (http://www.digitalmindstudio.ch/script.php?id=4&langue=en)
Title: Re:Custom Inventory GUI
Post by: Darth Mandarb on Tue 13/01/2004 16:27:57
Timosity - Thanks!  You got me started in the understanding process!

Dorcan - That site just rocks!!  It's the best tutorials site I've seen yet!  Awesome!

If anybody else has questions and/or wisdom to share please do so!  

Thanks guys!

])]V[
Title: Re:Custom Inventory GUI
Post by: Pet Terry on Tue 13/01/2004 18:03:30
I've done inventory in which you have only one mouse cursor mode to use and you either left click, right click or double left click items to select, interact or examine them. It's bit more complex to do (couldn't script it without help :P ) but I may post it here someday, if I remember.

At the moment only thing it needs are those arrows you use to scroll it, but I think I now know how they work...
Title: Re:Custom Inventory GUI
Post by: Darth Mandarb on Wed 14/01/2004 23:11:45
I am now bald.

Because I've pulled all my hair out trying to get this to work.

Here's my script:


// The Inventory GUI
{
if (interface == 4)
Ã, Ã, Ã, if (button==0) { // Close Button
Ã, Ã, Ã, GUIOff(4);
Ã, Ã, Ã, SetDefaultCursor();
Ã, Ã, Ã, } else
Ã, Ã, Ã, if (button==1) { // Use Button
Ã, Ã, Ã, SetCursorMode(3);
Ã, Ã, Ã, SetMouseCursor(2);
Ã, Ã, Ã, } else
Ã, Ã, Ã, if (button==2) { // Select Button
Ã, Ã, Ã, SetCursorMode(2);
Ã, Ã, Ã, SetMouseCursor(6);
Ã, Ã, Ã, } else
Ã, Ã, Ã, if (button==5) { // UP arrow
Ã, Ã, Ã,  if (game.top_inv_item>0)
Ã, Ã, Ã,  game.top_inv_item=game.top_inv_item-game.items_per_line;
Ã, Ã, Ã, } else
Ã, Ã, Ã, if (button==6) { // DOWN arrow
Ã, Ã, Ã,  if (game.top_inv_item < game.num_inv_items-game.num_inv_displayed)
Ã, Ã, Ã,   game.top_inv_item=game.top_inv_item+game.items_per_line;
Ã, Ã, Ã, }
}
// END INVENTORY GUI

** I have also added the SetInvDimensions in the game_start script. **

PROBLEMS:
I still can't actually select the inventory, even though I can see them.

What am I doing wrong?

])]V[
Title: Re:Custom Inventory GUI
Post by: Scorpiorus on Wed 14/01/2004 23:38:27
See haven't you handle inventory click in script option ticked somehow.

If not, you should be able to select an item in MODE_USE (#2) mode. Place a Display() function inside:
...
if (button==2) { // Select Button
  Display("MODE_USE");
  SetCursorMode(2);
  SetMouseCursor(6);
} else
...
to check if the mode is set at all.

Another thing is that SetInvDimensions() affects items clickable area. What if you temporarily remove it (adjust the values)?


EDIT: maybe its a copy/paste issue but the script should be:

if (interface == 4) {
  if (button==0) { // Close Button
  GUIOff(4);
  SetDefaultCursor();
  } else
  if (button==1) { // Use Button
  SetCursorMode(3);
  SetMouseCursor(2);
  } else
  if (button==2) { // Select Button
  SetCursorMode(2);
  SetMouseCursor(6);
  } else
  if (button==5) { // UP arrow
   if (game.top_inv_item>0)
   game.top_inv_item=game.top_inv_item-game.items_per_line;
  } else
  if (button==6) { // DOWN arrow
   if (game.top_inv_item < game.num_inv_items-game.num_inv_displayed)
   game.top_inv_item=game.top_inv_item+game.items_per_line;
  }
}
Title: Re:Custom Inventory GUI
Post by: Darth Mandarb on Thu 15/01/2004 00:27:42
Scorpiorus you have saved my sanity (and my hair is growing back).

I had, for some reason, ticked the Handle inventory click in script ... not sure why.

But it's working now!

1,000,000 thanks!!
Title: Inventory GUI ** NEW PROBLEM **
Post by: Darth Mandarb on Thu 22/01/2004 22:08:17
I've made some changes in my game and now my inventory GUI isn't functioning properly.

Here's what I changed:
- New main GUI which is popped-up by the mouse.x location.
(If the mouse.x < 5 the gui pops up.  Then if the mouse.x > 80 (the width of the GUI) and the GUI is on, it shuts the gui off and changes the cursor back.)
- I have removed 'Talk' from the 'Standard Cursors'.

Okay ...  here's my INVENTORY GUI script:
[color=000055]
// The Inventory GUI
if (interface == 4)
{
 if (button == 0) { // Close Button
   GUIOff(4) & SetDefaultCursor();
   } else
 if (button == 1) { // USE
   SetCursorMode(3);
   SetMouseCursor(6);
   } else
 if (button == 3) { // SELECT
   SetCursorMode(2);
   SetMouseCursor(6);
   } else
 if (button == 4) { // DETAILS
   SetCursorMode(1);
   SetMouseCursor(6);
   } else
 if (button == 5) { // UP arrow
    if (game.top_inv_item>0)
    game.top_inv_item=game.top_inv_item-game.items_per_line;
   } else
 if (button == 6) { // DOWN arrow
    if (game.top_inv_item < game.num_inv_items-game.num_inv_displayed)
     game.top_inv_item=game.top_inv_item+game.items_per_line;
   }
 }
// END INVENTORY GUI
[/color]
Problems
- When I click the up arrow it changes the cursor mode to 5 (Take).  The arrow functions (scrolls), but the cursor changes and I can't figure out why.
- Button 3, it changes to CursorMode(1) (look) and not mode 2 (and doesn't use the SetMouseCursor)
- Button 4, it changes to CursorMode(2) (interact) and not mode 1 (and doesn't use the SetMouseCursor)

I thought that by taking out a Standard Cursor that these were somehow -1 each or so.  So I tried adding 1, subtracting 1, and just switching them around.  All to no avail.

Any why on earth would the up arrow change to 'Talk' ...

I'm clueless. :(
Title: Re:Custom Inventory GUI
Post by: Dorcan on Thu 22/01/2004 23:48:06
Hum :
GUIOff(4) & SetDefaultCursor();
should be
GUIOff(4);
SetDefaultCursor();
no ?

I don't see any other errors... Maybe you could export your gui and let us download it, it would be easier to find a solution
Title: Re:Custom Inventory GUI
Post by: Darth Mandarb on Fri 23/01/2004 02:17:02
Here is the uploaded file:
GUIProblem ZIP (~1.2MB) (http://www.twin-design.com/thehouse/GUIproblem.zip)
(that was as small as I could make it!)

Here's the GUI:
(http://www.twin-design.com/thehouse/graphics/00_gui.gif)

Here's the problem:
Use Item - this button functions as it should
Select Item - this button is currently set to 'Set Cursor Mode' and does what it should, but I want it to 'Run Script' and do what is in the GUI script.
Item Details - same as above ...
Up Arrow - does what it should, but the cursor for some reason becomes the 'Take' cursor.  (and I checked ... it's actually setting that cursor mode, not just the cursor graphic)
Down Arrow - functions as it should.
Close - Does what it should.

NOTE : This build is just the ground floor and if you try to go up or down or out (upstairs, basement, or garage) it'll crash out on you!  

I wasn't sure how to export just the GUI, so this is everything (but I deleted all but 1 of the rooms!).

Thanks for any help you can give fellas!!
Title: Re:Custom Inventory GUI
Post by: Dorcan on Fri 23/01/2004 03:55:51
Yep, here's  the problem :

if (interface == 8)
{
Ã, Ã, Ã, if (button == 2) // The WALK button
Ã, Ã, Ã,   SetCursorMode(0) & GUIOff(7) & GUIOff(8);}{
Ã, Ã, Ã, if (button == 3) // The LOOK button
Ã, Ã, Ã,   SetCursorMode(1) & GUIOff(7) & GUIOff(8);
Ã, Ã, Ã, if (button == 4) // The INTERACT button
Ã, Ã, Ã,   SetCursorMode(2) & GUIOff(7) & GUIOff(8);
Ã, Ã, Ã, if (button == 5) // The TAKE button
Ã, Ã, Ã,   SetCursorMode(5) & GUIOff(7) & GUIOff(8);
Ã, Ã, Ã, if (button == 6) // The POCKETS button
Ã, Ã, Ã,   GUIOff(7) & GUIOff(8) & GUIOn(4);
Ã, Ã, Ã, if (button == 7) // The SAVE button
Ã, Ã, Ã,   GUIOff(7) & GUIOff(8) & SetDefaultCursor();
Ã, Ã, Ã, if (button == 8) // The LOAD button
Ã, Ã, Ã,   GUIOff(7) & GUIOff(8) & SetDefaultCursor();
Ã, Ã, Ã, if (button == 9) // The QUIT button
Ã, Ã, Ã,   GUIOff(7) & GUIOff(8) & GUIOn(0) & SetMouseCursor(6);
Ã, Ã, Ã, if (button == 10) // The ABOUT button
Ã, Ã, Ã,   GUIOff(7) & GUIOff(8) & SetDefaultCursor();
Ã, Ã, Ã, }
// END OF MAIN GUI
}

As you can guess, the code in blue is executed everytime a gui button is clicked, even if it isn't on the interface 8...
So just remove the red brackets and the problem will be resolved.

If I can suggest you something, don't add unuseful brackets hehe  :P

Btw, really cool effect when walls fade in or out ;)
Title: Re:Custom Inventory GUI
Post by: Darth Mandarb on Fri 23/01/2004 05:18:42
That did the trick!

Thank you so much!

You have just earned a spot in the credits ;)

])]V[

PS
If you think the fading in the groundfloor is cool, wait till you see the upstairs!! ;)
Title: Re: Custom Inventory GUI
Post by: monkey0506 on Fri 04/03/2005 16:49:08
I have some questions in regard to the lines like:

   if (button == 3) // The LOOK button
     SetCursorMode(1) & GUIOff(7) & GUIOff(8);


Is the use of the '&' operator legal here?  If so, has it always been like this, or is it just like that in 2.7?  In any case, is this considered good scripting, or would it be better and/or easier to read if brackets had been used, i.e.:

   if (button == 3) { // The LOOK button
     SetCursorMode(1);
     GUIOff(7);
     GUIOff(8);
     }
Title: Re: Custom Inventory GUI
Post by: Scorpiorus on Sat 05/03/2005 19:03:38
Yes, it would work and it worked in all versions. But as a general rule it is better to use braces as you pointed out.
Title: Re: Custom Inventory GUI
Post by: Mr. Mozzarella on Sat 05/03/2005 20:40:49
Is it possible to change the space between two inventory objects? My sprites are about 30x30 but the space between them is almost the double size. Due to that I only get 3 or 4 objects in a row and that doesn't look very good.
Title: Re: Custom Inventory GUI
Post by: Scorpiorus on Sat 05/03/2005 21:46:23
Yes, take a look at the SetInvDimensions function in the manual. Experiment passing less/greater values than the default ones: 40 x 22. The function changes item cell size, not the item sprite size so it should do the trick.
Title: Re: Custom Inventory GUI
Post by: storycatchermike on Mon 18/04/2005 03:52:27
I have a problem. When I interact with an inventory item, it picks the item up, but the item doesn't appear in the box in the iconbar. What do I have to do to make it appear in the iconbar?
Title: Re: Custom Inventory GUI
Post by: strazer on Mon 18/04/2005 04:21:04
Manual: Tutorial -> Setting up the game -> Inventory -> 3rd to last paragraph.
(INVSHR) should do the trick.
Title: Re: Custom Inventory GUI
Post by: storycatchermike on Mon 18/04/2005 15:58:28
Quote from: strazer on Mon 18/04/2005 04:21:04
Manual: Tutorial -> Setting up the game -> Inventory -> 3rd to last paragraph.
(INVSHR) should do the trick.
Thanks, man, that helped. I guess I forgot to look in the manual for that. Thanks for the help.
Title: Custom Inventory GUI
Post by: on Fri 22/12/2006 02:04:05
I'm having a hard time on my custom inventory GUI...

I just can't use the inventory items of the GUI on other thing... Actually I can't select the items, which I can see there with no problem... When I click on the icons nothing happens, the cursor mode doesn't change.

My game was started from zero (I didn't use the standard AGS template) so the cursor modes are all different !!
Title: Re: Custom Inventory GUI
Post by: petaglair on Wed 18/04/2007 19:01:04
hi
i've made a custom inventory screen. But i don't know how to have the inv items selectable in order to use them in the game.
The previous posts were hard to understand for me.
Please help
thanx

Pétaglair
Title: Re: Custom Inventory GUI
Post by: Scorpiorus on Thu 19/04/2007 20:23:09
First of all make sure the Handle inventory clicks in script option is not ticked.

Next, to be able to select an inventory item change the cursor mode to Interact, for example:

on showing your custom inventory GUI:

mouse.Mode = eModeInteract; // first set cursor mode to Interact
gMyInventory.Visible = true; // then show the GUI


where gMyInventory is the Script O-Name of your inventory GUI.
Title: Re: Custom Inventory GUI
Post by: petaglair on Thu 19/04/2007 21:46:09
ok

that did the trick
thanx a lot scorpiorus

Pétaglair
Title: broken link
Post by: Fuchs on Wed 08/02/2012 09:40:49
Quote from: Dorcan on Tue 13/01/2004 09:02:45
Timosity's explanations are good, but in this case the "use" button is for selecting the object, so if someday you'll need the "interact button" in your inventory, you can find my tutorial here

http://www.digitalmindstudio.ch/script.php?id=4&langue=en (http://www.digitalmindstudio.ch/script.php?id=4&langue=en)

Hey Dorcan ,the link to your page seems to be not working. Is there a way for me to still see the turorial?!
I am really keen on finding out how to creat a custom inventory, thats one of the most important things for me right now!
Thank you in advance!
Title: Re: Custom Inventory GUI
Post by: Khris on Wed 08/02/2012 09:55:38
The post you quoted is OVER EIGHT YEARS OLD.

Current versions of AGS allow the Inventory to be edited, so there's no need to create a replacement from scratch.
There are tons of threads about this already, please use the search.