Using inventory on objects in the room.

Started by Cluey, Thu 15/12/2011 21:50:12

Previous topic - Next topic

Cluey

Right. It's been a while but I decided to try my hand at AGS again. Anyway, I opened up my old project and the first real puzzle involves getting a lift working using some tools.

So anyway, I've don't inventory interactions before but I can't figure out why this isn't working. It parses the game fine but when I use the tools on the lift nothing happens.

Code: ags
function oObject0_UseInv ()
{
  if (player.ActiveInventory == (iTools)) {
    cEgo.Walk(225, 138, eBlock);
    player.Say("&42 Just gotta rejigger the thingymabob!");
    object[0].SetView(36);
  }
  else
  {
    player.Say("Nope");
  }
}


Aramore
My webcomic.

steptoe

Use

Code: ags

if (player.ActiveInventory == iTools) {




Cluey

#2
Quote from: steptoe on Thu 15/12/2011 21:59:10
Use

Code: ags

if (player.ActiveInventory == iTools) {





Yeah, I actually figured it out shortly after I posted the thread. There's some erroneous spaces and symbols. Also I mean to set graphic rather than view.
Aramore
My webcomic.

steptoe

Hi

You may want to Name your objects as it makes it easier when looking through the code.

object[0] could be oLift or something.


Khris

Cluey, so what was the actual problem?
The code in the first post looks fine, the brackets shouldn't break anything; the reason for not getting any reaction from the game seems to have been missing linkage in the object's event properties, right?

Cluey

Quote from: Khris on Thu 15/12/2011 22:22:09
Cluey, so what was the actual problem?
The code in the first post looks fine, the brackets shouldn't break anything; the reason for not getting any reaction from the game seems to have been missing linkage in the object's event properties, right?

Well, that's probably my fault. I initially just wrote the script into the room script (as this is where the events handler puts scripts anyway), but I guess the events handler does something under the hood or on the global script to link it? Since when I used that and used the same (albeit without the erroneous spaces and brackets) script it worked fine, even though the exact same script is occupying the exact lines on the room script.
Aramore
My webcomic.

monkey0506

The linkage is handled by the Events pane (in the same place as the Properties, but click on the lightning bolt icon).

Whatever function name is listed there is the function that's going to get called.

Khris

#7
Functions like that don't get called automatically; when the event occurs, AGS only looks at the event properties and calls whatever function is entered into the field next to the event. If there's nothing there, nothing's gonna happen, regardless of the function name. You can call the function Trololololol, but you must put its name into the field to get AGS to use it.

The cool thing about this is that you can call the same function from multiple events. Comes really in handy if for instance you code a keypad using GUI buttons. A single function can get the button from the GUIControl parameter and process the click.

SMF spam blocked by CleanTalk