Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: GoToHellDave on Tue 02/10/2012 09:15:54

Title: How do I tell if a player has a certain inventory item?
Post by: GoToHellDave on Tue 02/10/2012 09:15:54
Hi Veterans.

I'm aware that there is already a thread on this topic but it is nearly ten years old and it doesn't seem to be relevant anymore.

I'm currently trying to detect if the player has a certain item the inventory and, if he does, turn on a specific dialogue option. Here is the code I am using:

Quoteif(cDave.inv6 != 0)
  {
option-on 7
  {
   else
   {
option-off 7
   }

I get an error telling me that "inv6" isn't a public member of 'character'. What am I doing wrong?

As always, any help is very much appreciated.
Title: Re: How do I tell if a player has a certain inventory item?
Post by: Crimson Wizard on Tue 02/10/2012 09:25:36
There's no such variable as inv6 in character class. You mean "inv" array, in which case you access its elements by index, putting the index in square brackets like
Code (ags) Select

cDave.inv[6];


I do not know which version of AGS you are using, but in the recent version "inv" is considered obsolete. If you are using AGS 3.+, I'd recommend to use one of the following:
Use either Character.HasInventory function (if you do not need to know exact quantity, just the fact of presence)
Code (ags) Select

cDave.HasInventory(iInventoryName);

or Character.InventoryQuantity[] array (the exact substitute for "inv"):
Code (ags) Select

cDave.InventoryQuantity[6];

Title: Re: How do I tell if a player has a certain inventory item?
Post by: GoToHellDave on Tue 02/10/2012 09:47:42
Thanks for the quick reply. Unfortunately I'm still having trouble. I don't know if this is because I'm doing this in the dialogue script or because I've made another schoolboy error. My code now looks like this:

Code (AGS) Select

  if(cDave.HasInventory(iFFPass))
  {
option-on 7
  {
   
  else
  {
option-off 7
  }


and I get the error "parse error at 'else'"

Also, if I remove the 'else' section of the statement I still get the same error.

Can you tell me what I'm doing wrong?

Title: Re: How do I tell if a player has a certain inventory item?
Post by: Crimson Wizard on Tue 02/10/2012 10:06:27
Your second curly bracket is wrong: you use opening one '{', while you should use closing one '}' :)
Title: Re: How do I tell if a player has a certain inventory item?
Post by: GoToHellDave on Tue 02/10/2012 10:30:24
Derp. Another silly mistake.

Thanks for the help.