Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: fratello Manu on Fri 12/02/2021 22:43:59

Title: Best way to use inventory on something, from script?
Post by: fratello Manu on Fri 12/02/2021 22:43:59
Hi everyone!

I can't find a working way , from script (no mouse clicks anywhere, things will happen by typing commands, parser-style) , to do something like:

- use iKey (which is in my inventory) on Hotspot1, or
- use iKey on Object1, or
- use iKey on Character1, or
- use iKey on iOtherInventoryWhichIOwn.

I know I have to deal with RunInteraction and eModeUseWith, but I can't understand in which event, with which syntax.... etc

Thanks!!! :wink:
Title: Re: Best way to use inventory on something, from script?
Post by: Crimson Wizard on Sat 13/02/2021 01:06:10
The two ways from the top of my head are:

1.  All these objects have "Use inventory on..." event. Create event functions for them. Then when reacting to the player's command do this:
Code (ags) Select

SomeObject.RunInteraction(eModeUseinv);

this will run "use inventory on" event, if there's a connected function.

To pass what item is used you can set player.ActiveInventory. Or your own global variable of type InventoryItem*.

2. You can keep using one "interact" function for all events, but then set active inventory item before calling it and setting it to null after calling it. Then inside this event function you just check whether active inventory is set, and that would mean that item is used.

Title: Re: Best way to use inventory on something, from script?
Post by: fratello Manu on Mon 15/02/2021 11:39:24
I was already doing like that... so I found out that the error was somewhere else!!!
thanks!