SOLVED: object not recognized by UseInv

Started by johanvepa, Mon 03/06/2013 22:14:11

Previous topic - Next topic

johanvepa

I am in a bit of a fix here.

This shouldn't be a technical problem at all, more of a simple coding error, I just can't seem to put my finger on where the error is.

Would like to hear from anyone who's had similar problems.

In one room, there's an Inn that cEgo can visit by opening the door. He can look at the door, interact with it, and use his inventory on it.

The following code
Code: AGS

function inndoor_UseInv()
{
if (cEgo.ActiveInventory == inventory[19]) //which is a dagger
  {
  Display("You stick a dagger into the doorpost as an ominous warning.");
  }
// lots of other stuff...
}

...works just fine. Message is displayed as it should, in the room with the inn.

Now, I go into another room. Here, the Sheriff's house lies, with promises of jailbreaks and escapes across the rooftops. This door, I can look at and interact with, too.

But this code:
Code: AGS

function oSheriffdoor_UseInv()
{
if (cEgo.ActiveInventory == inventory[19])
  {
  Display("You stick a dagger into the doorpost as an ominous warning.");
  }
// and so on and so forth
}

...does absolutely nothing. I can look at this door too, I can interact with it, but when it comes to using inventory on it, nothing happens. Not even an error message. Nothing.

Both of the objects inndoor and oSheriffdoor are baselineoverridden (baseline 1).

I'm severely puzzled.

Khris

The first thing I'd look at: is the "use inventory on oSheriffdoor" event linked to the function?

Btw, you can use the name of the inventory item, for instance "iDagger". InventoryItems are global objects und can be accessed like that in every script, unlike a room's Objects.

johanvepa

Quote from: Khris on Mon 03/06/2013 22:34:30
is the "use inventory on oSheriffdoor" event linked to the function?

I'm not sure what you mean by this.

Khris

Go to the room editor, select Objects, select the door in queston, click the lightning bolt in the properties window.
Now look at the line that says "use inventory on object". Next to it should be the name of function: "oSheriffdoor_UseInv".
This is where an engine event is linked to a function in a script; this connection isn't there by default, it has to be established for each event.

johanvepa

Quote from: Khris on Mon 03/06/2013 22:46:00
Go to the room editor, select Objects, select the door in queston, click the lightning bolt in the properties window.
Now look at the line that says "use inventory on object". Next to it should be the name of function: "oSheriffdoor_UseInv".
This is where an engine event is linked to a function in a script; this connection isn't there by default, it has to be established for each event.


That was it. So simple.

You know, I do this ALL THE TIME! And though I am proud of myself when I do remember it, whenever I copy a function from one room to another (in this case, I copied the function from the room with the inn to the room with the Sheriff building), I forget about linking the function to the event.

And if I regret scripting a function, I delete it from the room script and forget about the event link, and then the game crashes.

Anyway, thanks for the hint, I just knew it'd be something as embarassingly simple as this.

SMF spam blocked by CleanTalk