Adventure Game Studio | Forums

AGS Support => Beginners' Technical Questions => Topic started by: viktor on 21 Nov 2020, 12:57

Title: (Solved) Thumbleweed: Usin Inventory items on Objects
Post by: viktor on 21 Nov 2020, 12:57
I'm having some trouble understanding how to make this work. I'm trying to make my character open a footlocker. For the most part it works but even though the action is successful my player character still says "That won't do any good". I've looked through the manual and simply can't find any example of an item being used on an object.

Code: Adventure Game Studio
  1. function oCFootlocker_UseInv()
  2. {
  3.   if (player.ActiveInventory == iFranksKey) {
  4.     player.Walk(171, 119, eBlock, eWalkableAreas);
  5.     oCFootlocker.Visible = false;
  6.     oOFootlocker.Visible = true;}
  7.    
  8. //Else
  9.   else player.Say("I can't do that.");
  10. }
Title: Re: Thumbleweed: Usin Inventory items on Objects
Post by: eri0o on 21 Nov 2020, 13:07
Are you sure your oCFootlocker_UseInv is linked in the Editor? See  https://adventuregamestudio.github.io/ags-manual/FAQ.html

You need to open the events (lighting bolt icon) in the oCFootlocker object in the Editor, find the Use Inventory event and link from there.
Title: Re: Thumbleweed: Usin Inventory items on Objects
Post by: Crimson Wizard on 21 Nov 2020, 13:30
even though the action is successful my player character still says "That won't do any good".

BTW, is this "That won't do any good" message shown for unhandled interactions if everything else failed?

EDIT: oh yes, it is in Thumbleweed template, so apparently the oCFootlocker_UseInv is not run at all.

The good way to test if the function is run is to place a break point there (F9) or display some message, like Display("it runs");
Title: Re: Thumbleweed: Usin Inventory items on Objects
Post by: viktor on 21 Nov 2020, 19:23
Are you sure your oCFootlocker_UseInv is linked in the Editor? See  https://adventuregamestudio.github.io/ags-manual/FAQ.html

You need to open the events (lighting bolt icon) in the oCFootlocker object in the Editor, find the Use Inventory event and link from there.

The object is linkedin the Editor.

(https://i.ibb.co/hLKRyy3/Screenshot-1.png)

even though the action is successful my player character still says "That won't do any good".

BTW, is this "That won't do any good" message shown for unhandled interactions if everything else failed?

EDIT: oh yes, it is in Thumbleweed template, so apparently the oCFootlocker_UseInv is not run at all.

The good way to test if the function is run is to place a break point there (F9) or display some message, like Display("it runs");

The function runs. oCFootlocker dissaperars and oOFootlocker appears. So apparently the script runs. I'm doing something wrong regarding the else and if's probably, since the action is performed and the character still says the unhandled text.
Title: Re: Thumbleweed: Usin Inventory items on Objects
Post by: Crimson Wizard on 21 Nov 2020, 19:39
Ah! it does the job, but prints unhandled text, looks like I misunderstood.

I am not an expert in that template, but from the quick look, you have to call Verbs.Unhandled(); to receive such response. You could maybe try placing a break point inside Verbs::Unhandled() function and when game gets there check the Call Stack panel and see which way did it come there.
Title: Re: Thumbleweed: Usin Inventory items on Objects
Post by: Cassiebsg on 21 Nov 2020, 23:20
Uhm, I'm not familiar with the tumbleweed template, but doesn't it handle all the "verbs" using any_click? Can it be that it's actually running both scripts? And thus you get your successful action AND the unhandled via the any click? Try deleting the any_click from the event (you can always add it again afterwards) and see if it fixes the problem.  (wtf)
Title: Re: Thumbleweed: Usin Inventory items on Objects
Post by: Crimson Wizard on 21 Nov 2020, 23:30
Uhm, I'm not familiar with the tumbleweed template, but doesn't it handle all the "verbs" using any_click? Can it be that it's actually running both scripts?

Yes, this is actually the case, AGS calls "use inv" event first, and then "any click".
Title: Re: Thumbleweed: Usin Inventory items on Objects
Post by: viktor on 22 Nov 2020, 07:34
Uhm, I'm not familiar with the tumbleweed template, but doesn't it handle all the "verbs" using any_click? Can it be that it's actually running both scripts?

Yes, this is actually the case, AGS calls "use inv" event first, and then "any click".

Yes that was the issue.

But how can I make the character interact with the object if I remove that function? How can I make him look at the footlocker, door or anything for that matter?
Title: Re: Thumbleweed: Usin Inventory items on Objects
Post by: Crimson Wizard on 22 Nov 2020, 10:19
But how can I make the character interact with the object if I remove that function? How can I make him look at the footlocker, door or anything for that matter?

Don't remove any click, remove use inv from events instead, and just call oCFootlocker_UseInv from oCFootlocker_AnyClick (in case action was "use inv").
Title: Re: Thumbleweed: Usin Inventory items on Objects
Post by: viktor on 22 Nov 2020, 13:45
But how can I make the character interact with the object if I remove that function? How can I make him look at the footlocker, door or anything for that matter?

Don't remove any click, remove use inv from events instead, and just call oCFootlocker_UseInv from oCFootlocker_AnyClick (in case action was "use inv").

That did it :). Thank's guys :)
Title: Re: (Solved) Thumbleweed: Usin Inventory items on Objects
Post by: Khris on 22 Nov 2020, 14:20
The proper way is to only use the AnyClick event and handle using inv items just like any other verb:

Code: Adventure Game Studio
  1.   else if (Verbs.UsedAction(eGA_UseInv)) {
  2.     // check player.ActiveInventory, etc.
  3.   }