UseInv() function

Started by geork, Tue 17/03/2009 20:30:07

Previous topic - Next topic

geork

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:
Code: ags

   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!

Ghost

To remove an item from the inventory, use loseInventory, I don't think you can even set an inventory items' visibility.

geork

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:
 
Code: ags

   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

Dualnames

 
Code: ags

   function okeyy_UseInv(){
if (player.ActrveInventory==iKey) {
//code here
}  
}
  


Not sure, I got what you meant. Hopefully I did.
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Trent R

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
Code: ags
//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
To give back to the AGS community, I can get you free, full versions of commercial software. Recently, Paint Shop Pro X, and eXPert PDF Pro 6. Please PM me for details.


Current Project: The Wanderer
On Hold: Hero of the Rune

geork

 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.

OneDollar

#6
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
Code: ags

function oRoom1_UseInv()
{

}

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

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.

geork

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

OneDollar

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.

geork

  Thanks!!!
   yep, it all works fine now, thanks to the genius of you people, thankyou very much
    (lol, option 4)
  cya

SMF spam blocked by CleanTalk