Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: viktor on Sat 21/11/2020 12:57:42

Title: (Solved) Thumbleweed: Usin Inventory items on Objects
Post by: viktor on Sat 21/11/2020 12:57:42
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 (ags) Select
function oCFootlocker_UseInv()
{
  if (player.ActiveInventory == iFranksKey) {
    player.Walk(171, 119, eBlock, eWalkableAreas);
    oCFootlocker.Visible = false;
    oOFootlocker.Visible = true;}
   
//Else
  else player.Say("I can't do that.");
}
Title: Re: Thumbleweed: Usin Inventory items on Objects
Post by: eri0o on Sat 21/11/2020 13:07:28
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 Sat 21/11/2020 13:30:08
Quote from: viktor on Sat 21/11/2020 12:57:42even 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 Sat 21/11/2020 19:23:54
Quote from: eri0o on Sat 21/11/2020 13:07:28
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)

Quote from: Crimson Wizard on Sat 21/11/2020 13:30:08
Quote from: viktor on Sat 21/11/2020 12:57:42even 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 Sat 21/11/2020 19:39:16
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 Sat 21/11/2020 23:20:03
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 Sat 21/11/2020 23:30:59
Quote from: Cassiebsg on Sat 21/11/2020 23:20:03
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 Sun 22/11/2020 07:34:33
Quote from: Crimson Wizard on Sat 21/11/2020 23:30:59
Quote from: Cassiebsg on Sat 21/11/2020 23:20:03
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 Sun 22/11/2020 10:19:35
Quote from: viktor on Sun 22/11/2020 07:34:33
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 Sun 22/11/2020 13:45:16
Quote from: Crimson Wizard on Sun 22/11/2020 10:19:35
Quote from: viktor on Sun 22/11/2020 07:34:33
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 Sun 22/11/2020 14:20:44
The proper way is to only use the AnyClick event and handle using inv items just like any other verb:

Code (ags) Select
  else if (Verbs.UsedAction(eGA_UseInv)) {
    // check player.ActiveInventory, etc.
  }