Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: FanOfHumor on Mon 18/04/2022 16:59:55

Title: (Solved)Have a button handle the interactions of an inventory item.
Post by: FanOfHumor on Mon 18/04/2022 16:59:55
I have a button that displays an inventory item in my custom inventory. I don't have an inventory window but instead I have buttons in place of where the inventory items should be placed.Its really hard to explain so i'll try explaining with pictures.

I have a button for interactions.
(https://i.imgur.com/A1DSuzu.jpg)
and an inventory item for receiving the actions as events.
(https://i.imgur.com/4xF5HFM.jpg)
I want the inventory item to recognize events
from the buttons interactions.(As if The inv-item was clicked instead of the object)
(https://i.imgur.com/4zSFr7V.jpg)
if ikey(the button) has an item used on it then ikey2(inv-item) should recognize it as (https://i.imgur.com/BzgF2er.jpg).
And so on with the other events.
I hope I explained it clear enough.
Thanks in advance.
Title: Re: Have a button handle the interactions of an inventory item.
Post by: eri0o on Mon 18/04/2022 22:43:04
I cannot understand which type of AGS struct ikey is. Is it an object, a button or an inventory item?

If it's an inventory item, you can call it's interaction using RunInteraction
Code (ags) Select
ikey.RunInteraction(eModeInteract);
Title: Re: Have a button handle the interactions of an inventory item.
Post by: Khris on Tue 19/04/2022 00:00:32
You can use
Code (ags) Select
  if (mouse.Mode == eModeUseinv) { ... }
Title: Re: Have a button handle the interactions of an inventory item.
Post by: FanOfHumor on Tue 19/04/2022 01:41:53
Oops! I called the button an object. ikey is a button and ikey2 is an inventory item. Will try that Khris when I get a chance. Although something about that doesn't sound right for a button .I could be wrong.
Title: Re: Have a button handle the interactions of an inventory item.
Post by: FanOfHumor on Tue 19/04/2022 02:25:39
How do I get the global inventory item ("item") to equal the selected inventory item.

I added this to the basic function do_inventory_action(MouseButton button, InventoryItem* item)
Code (ags) Select
  Object *o = Object.GetAtScreenXY(mouse.x, mouse.y);
  if (o != null && o.GetProperty("inventory")==true)
  {
    mouse.Mode=eMouseLeftInv;
  }

Sorry if my explanation is fragmented and confusing.
Title: Re: Have a button handle the interactions of an inventory item.
Post by: Khris on Tue 19/04/2022 12:06:38
eMouseLeftInv is a click type, not a mouse mode.
If you want to set the key as active cursor after clicking the button, you can do
Code (ags) Select
  player.ActiveInventory = ikey2;
This should also change the mouse mode to  eModeUseinv.
Title: Re: Have a button handle the interactions of an inventory item.
Post by: eri0o on Tue 19/04/2022 13:57:19
I think I am almost understanding... Are you making a room that works like an inventory, with objects being the things the player added to the inventory?
Title: Re: Have a button handle the interactions of an inventory item.
Post by: FanOfHumor on Tue 19/04/2022 16:35:25
Its with buttons being the things the player added to the inventory.Its definitely figured out by now. Thanks for your help both of you.