Need help with UseInv (SOLVED)

Started by Woten, Mon 15/04/2013 00:05:30

Previous topic - Next topic

Woten

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?

Crimson Wizard

#1
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

function cTV_UseInv()


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

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

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

PrintItemName(iRemote);

PrintItemName(iKey);

PrintItemName(iSomeOtherItem);


Woten

Thank you, this fixed the problem, and also clarified a few things for me :D

SMF spam blocked by CleanTalk