Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: a157thhokage on Tue 07/09/2010 16:08:53

Title: Script for "Use inventory on object" *SOLVED*
Post by: a157thhokage on Tue 07/09/2010 16:08:53
What should the script look like for Use inventory on object"?
Title: Re: Script for "Use inventory on object"
Post by: Matti on Tue 07/09/2010 16:19:30
Like this:


function oOBJECTNAME_UseInv()
{

}


BUT you don't have to write that yourself. Just go the object's events pane to the right and select "Use inventory on object" .. then the section above will be created automatically.

Tip: Do the tutorial  ;)
Title: Re: Script for "Use inventory on object"
Post by: hedgefield on Tue 07/09/2010 16:25:32
You select the object or hotspot you want, then click the Use Inventory On Object option in the Events tab and you should get a script similar to:

function oOBJECTNAME_UseInv() {
}


Then change that to say:

function oOBJECTNAME_UseInv() {
 if (cEgo.ActiveInventory == iITEMNAME) {
   // put your code here
 }
}
Title: Re: Script for "Use inventory on object"
Post by: a157thhokage on Wed 08/09/2010 12:32:06
Thnx anyway but that's not what i mean. I want to use a stick(already in inventory) and use the stick on an apple(object in room) so when i use the stick on the apple the apple goes in my inventory.What should be the script?         
Title: Re: Script for "Use inventory on object"
Post by: Matti on Wed 08/09/2010 13:16:07
It's exactly what you meant:


function oApple_UseInv() {
  if (cEgo.ActiveInventory == iStick) {
    player.AddInventory(iApple);
    oApple.Visible=false;
  }
}
Title: Re: Script for "Use inventory on object" *SEMI-SOLVED*
Post by: Khris on Wed 08/09/2010 14:42:59
In case this isn't clear, there's no technical connection whatsoever between a room object and an inventory item. Them representing the same thing is a concept outside of AGS.
Title: Re: Script for "Use inventory on object" *SEMI-SOLVED*
Post by: a157thhokage on Thu 09/09/2010 16:14:11
I tried the script u gave me but i cant drag the inventory item "Stick" out of the inventory box and click the stick with the apple.How should I proceed from here?
Title: Re: Script for "Use inventory on object" *SEMI-SOLVED*
Post by: Khris on Thu 09/09/2010 17:31:52
You don't need a special script unless you actually want to drag items. Usually the player clicks on an inventory item and the mouse cursor turns into it (mouse.Mode is now eModeUseinv). Now the player clicks on the object, and the object's _Useinv() is called, with player.ActiveInventory being the selected inv item.

This is all built-in default behavior and doesn't need to be scripted.
Title: Re: Script for "Use inventory on object" *SEMI-SOLVED*
Post by: a157thhokage on Thu 09/09/2010 18:07:06
Aghhhhhhhhh! I still dont get it. I really suck at scripting.
Title: Re: Script for "Use inventory on object" *SEMI-SOLVED*
Post by: Khris on Thu 09/09/2010 18:11:42
What does and doesn't work?
Please be more specific so we can help you.
Title: Re: Script for "Use inventory on object" *SEMI-SOLVED*
Post by: a157thhokage on Thu 09/09/2010 18:14:35
Ok thnx. Figured it out  :P