Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Woten on Mon 15/04/2013 00:05:30

Title: Need help with UseInv (SOLVED)
Post by: Woten on Mon 15/04/2013 00:05:30
I have a TV in the game, the TV screen is a character. And You have to use a remote control on the television

I have some code in place in order to trigger the broadcast: it looks like this "function cTV_UseInv(iRemote)"

But AGS gives me a parse error.

So, masters of AGS, how can I make it so it works?
Title: Re: Need help with UseInv
Post by: Crimson Wizard on Mon 15/04/2013 00:45:18
You can't make a function that takes certain item as parameter; functions take a variable of certain type (like InventoryItem*).
But in the case of "use inventory" event handlers - they don't take any parameters at all. You should have this created automatically by AGS:
Code (ags) Select

function cTV_UseInv()


Inside the function you may then check, what is the active player's item:
Code (ags) Select

function cTV_UseInv()
{
  if (player.ActiveInventory == iRemote)
  {
     // do something here
  }
}




Although this is not directly related, but if we discuss function parameters further, as I mentioned, they can't be declared as being equal to certain value (like iRemote), because that will defeat the purpose of parameter itself. Instead, they are variables, which means they may be of any value of given type.
For example:
Code (ags) Select

function PrintItemName(InventoryItem *some_item)
{
   Display("This item's name is: %s", some_item.Name);
}

This function will take a pointer to some inventory item, which may really be ANY item, in theory, and print its name.
You may then use this function with any item you want, like:
Code (ags) Select

PrintItemName(iRemote);

PrintItemName(iKey);

PrintItemName(iSomeOtherItem);

Title: Re: Need help with UseInv
Post by: Woten on Mon 15/04/2013 01:39:13
Thank you, this fixed the problem, and also clarified a few things for me :D