Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: geork on Tue 17/03/2009 20:30:07

Title: UseInv() function
Post by: geork on Tue 17/03/2009 20:30:07
Hey all!
  I've looked everywhere, tutorial, wiki, youtube, the local library, but I havent found any reference to the UseInv() function, and I'm not quite sure how it works. what I am hoping to achieve, is that one object is needed the get the other e.g. a hooked stick to get a key, which is in my case. I tried this code, but it doesn't want to work:

   function okeyy_UseInv(iKey) //iKey is the object required to use on okeyy, the object
{
if (brim ==1){    //brim = 1 when the player is in the right position
   okeyy.Visible = false;  //get rid of object (so to speak)
   player.AddInventory(iInvItem1); //add key
   GiveScore(5);
}
}

  but it doesn't like that, I can guess that maybe I need to reference some kind of ID for the iKey, but I really don't know how to do that, either.
    thanks for the help!
Title: Re: UseInv() function
Post by: on Tue 17/03/2009 22:28:59
To remove an item from the inventory, use loseInventory, I don't think you can even set an inventory items' visibility.
Title: Re: UseInv() function
Post by: geork on Wed 18/03/2009 10:05:25
That's not quite what I mean.
  there is an object in the room, okeyy, which is too high up for the character to reach unless he climbs on top of the shelf (in which case, brim = 1). But, he needs to use the inventory item iKey to get okeyy, as iKey is a hooked stick. when I looked on events for okeyy, it came up with the option to use an inentory item on it. clicking on it, it came up with the _UseInv() function, so it came up with:
 
   function okeyy_UseInv()
{
  }
 

  assuming, therefore, that I could somehow reference the iKey in the inventory, so that I could use it on the okeyy object.
   
   thanks
Title: Re: UseInv() function
Post by: Dualnames on Wed 18/03/2009 10:22:08
 
   function okeyy_UseInv(){
if (player.ActrveInventory==iKey) {
//code here

}
 


Not sure, I got what you meant. Hopefully I did.
Title: Re: UseInv() function
Post by: Trent R on Thu 19/03/2009 00:43:49
You're question (and script) would be a lot more readable if you renamed your objects (iKey to iStick, iInvItem1 to iRustyKey, or whatever).

It's possible that brim isn't getting set to 1, which is why your first script might not be running. Try a putting something like //in rep_exec
if (brim==1) {
  if (Game.DoOnlyOnce("brim is 1") {
    Display("brim=1 !! Yay!");
  }
}

Then try using the stick on the key.
Also, you could use the debugger/break points if you know how to use them.


~Trent
Title: Re: UseInv() function
Post by: geork on Thu 19/03/2009 20:57:50
 thanks for the advice guys!
   nope, I'm still not achieving much, even though I tried totally excluding the brim function. This is probabely my fault, as I have re-read what I wrote and find it difficult to understand, so I took tried to illustrate with keys (as I can't attatch any mpeg files)

-----------------|  (now select the istick, so the mouse pointer is now istick)
  (inventory)  |
                     |
   (istick)        |
-----------------
                            (istick, which is mouse pointer) -> (click on) (okeyy object).
               
                          okay, not quite good but I hope you get the idea. this is why, after surfing through the events for the okeyy object I alighted upon the UseInv function, in the hope of being able to achieve something when the okeyy object is clicked on by the inventory item.
   thanks
   PS: would the debugger/break point options be the match brace option? the toggle break point makes no sense.
Title: Re: UseInv() function
Post by: OneDollar on Thu 19/03/2009 22:41:38
Um, you aren't just typing the function okeyy_UseInv(iKey) function into the room script, are you? You need to link it to an action in order to make sure its run. In the room editor select your object then click the 'events' (lightning bolt) button. Click on 'Use inventory on object' then click the little button with the three dots next to it. This automatically generates the code
function oRoom1_UseInv()
{

}

in the room script. Now you need to add the rest of your function in there...

function oRoom1_UseInv()
{
  if (player.ActiveInventory == iKey) {
    //the function is called whenever an inventory item is used on the object, so we have to check if it was the
    //right item that was used. The item just used will be the player character's active one.
    if (brim==1) {  //if the brim variable has a value of one...
      okeyy.Visible = false;  //hide object okeyy
      player.AddInventory(iInvItem1);  //add inventory item iInvItem1 to the player character's inventory.
      GiveScore(5);  //add five to the score
    }else{
      player.Say("I'm not close enough");  //if brim is not equal to one. Don't strictly need this, but it'll tell
      //you if the script is running even when brim isn't equal to one.
    }
  }else{
    player.Say("I can't use that object there");  //if used a different object.
  }
}


Apologies if you'd already done this.
Title: Re: UseInv() function
Post by: geork on Sat 21/03/2009 14:24:08
Thankyou!
  yes, I had done that, but I must have gotten some things wrong, because now it works!!! but thankyou very much for yur help guys!
   My only nag is that, well, it's quite hard to actually click on the part of the key which will make it disapear... I wondered if there is a way where one can click on the key in general, not just a specific part.
   thanks
Title: Re: UseInv() function
Post by: OneDollar on Sat 21/03/2009 17:17:28
Quote from: geork on Sat 21/03/2009 14:24:08
I wondered if there is a way where one can click on the key in general, not just a specific part.

I assume you mean not having to click on a pixel where you've drawn the key, but rather clicking on one of the transparent pixels that are part of the key sprite? When you import a sprite into AGS you choose which bits are transparent and by default these can't be clicked on. You can turn this off in the general settings (it's the 'pixel-perfect click detection' option) but this means all your objects will be clickable as a rectangle which isn't usually wanted. A couple of alternative options...

1) Make a hotspot behind the key that's the size you want to be able to click in and give it the same description so that the player won't be able to tell it apart from the key. Then give it the same functions as interacting with the key, and make sure to set its .Enabled property to false when you take the key.

2) As above, but instead of duplicating the code make it all interactions with the hotspot call the relevant functions of the key.

3) Draw part of the background in with the key sprite (assuming it's going to stay stationary).

4) Draw the key bigger.
Title: Re: UseInv() function
Post by: geork on Sat 21/03/2009 21:05:48
  Thanks!!!
   yep, it all works fine now, thanks to the genius of you people, thankyou very much
    (lol, option 4)
  cya