Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: arrtisste36 on Wed 22/12/2010 18:45:16

Title: Selecting Inventory items
Post by: arrtisste36 on Wed 22/12/2010 18:45:16
I'm trying to implement a custom inventory GUI, but I can't figure out how to actually select an inventory item.  My interface is set up so that a left click interacts and a right click looks at. However, when I click on an item in the inventory, nothing happens. Can someone help me figure out how to select an item and use it in the game?
Title: Re: Selecting Inventory items
Post by: on Wed 22/12/2010 19:16:13
When you script your own functionality, make sure, in General Settings, to OVERRIDE the custom inventory functionality, otherwise clicks will just be processed by the game.
Once you have done that, create cases for ButtonInvLeft and ButtonInvRight and put your selfmade code there.
To select an inventory and "attach" it to the mouse, simply set it as player.ActiveInventory. (Careful, this is from top of my head and capital letters might be all wrong!)
Title: Re: Selecting Inventory items
Post by: arrtisste36 on Thu 23/12/2010 00:16:10
I'm sorry if this is a dumb question, but what specifically do I need to set as player.ActiveInventory?
Title: Re: Selecting Inventory items
Post by: Matti on Thu 23/12/2010 00:35:56
The item  ;)

cWhoever.ActiveInventory = iWhatever;
Title: Re: Selecting Inventory items
Post by: arrtisste36 on Thu 23/12/2010 01:04:44
Wouldn't that set a specific item as the inventory item? How do I make it so that the active item is whatever is being clicked on?
Title: Re: Selecting Inventory items
Post by: Matti on Thu 23/12/2010 01:16:00
[game.inv_activated] is the item the player last clicked, so something like this should work:

if (button == eMouseLeftInv) {
  cEgo.ActiveInventory=inventory[game.inv_activated];
}

I'm not completely sure as I'm not too familiar with custom inventory stuff, but I think it should work.
Title: Re: Selecting Inventory items
Post by: on Thu 23/12/2010 10:29:16
Either that, or you can use InventoryItem.GetAtScreenXY(int x, int y). That function is especially made for custom inventory windows, and will return whatever inventory is currently under the mouse (has been clicked). The AGS help file has an example how to use it, too.
Title: Re: Selecting Inventory items
Post by: Khris on Thu 23/12/2010 11:47:57
It's weird that a left-click on an inventory item does nothing; which mouse mode is the game in when the mouse is over the InvWindow?
Sure, you can change the script handling setting and use eMouseLeftInv code, but that shouldn't be necessary for just selecting an item. The default game e.g. does this just fine.

Also, with this code
  if (button == eMouseLeftInv) {
    cEgo.ActiveInventory=inventory[game.inv_activated];
  }

there won't ever be a null pointer error, while InventoryItem.GetAtScreenXY(int x, int y) might throw one. I only use the latter if I need the item when there wasn't a click.