Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: MiteWiseacreLives! on Wed 07/12/2016 23:48:18

Title: Problems checking an inventory item Property [solved]
Post by: MiteWiseacreLives! on Wed 07/12/2016 23:48:18
Sorry if I'm going to clog up the forums today  :-[
I cannot figure why the following gives me an error:
if (iInvHat1.GetProperty("IsHat"))
Error (line 43): Unexpected 'int'

IsHat is the Boolean property in the properties pane and set to true, so why not an integer??
Title: Re: Problems checking an inventory item Property
Post by: Crimson Wizard on Wed 07/12/2016 23:53:53
GetProperty always returns integer. "Boolean" is just a way to set them up in the editor.
I forgot if AGS script can automatically convert integers too boolean expression... maybe it actually can? Or maybe it cannot in some cases.
Anyway, to check property in a boolean way you can do this:
Code (ags) Select

if (iInvHat1.GetProperty("IsHat") != 0) // this means "is true"
{
}
if (iInvHat1.GetProperty("IsHat") == 0) // this means "is false"
{
}
Title: Re: Problems checking an inventory item Property
Post by: MiteWiseacreLives! on Thu 08/12/2016 00:18:31
thanks for our help CW
I added brackets and it seem to fix it.. was more to do with line 44 I guess.
Code (ags) Select
  InventoryItem *itemToSwap = player.ActiveInventory; 
 
  if (itemToSwap.GetProperty("isGlasses"))
  {
    glasV = itemToSwap.GetProperty("InvenView");
  }


this does not work:
Code (ags) Select

  InventoryItem *itemToSwap = player.ActiveInventory; 
 
  if (itemToSwap.GetProperty("isGlasses"))
    int glasV = itemToSwap.GetProperty("InvenView"); 
Title: Re: Problems checking an inventory item Property
Post by: Crimson Wizard on Thu 08/12/2016 00:22:42
Looks like a script compiler bug. But if it worked properly, that variable would exist only for that one line, which won't make much sense.
Title: Re: Problems checking an inventory item Property
Post by: MiteWiseacreLives! on Thu 08/12/2016 00:30:14
yes your right. I had to declare it at the top of the function for it to work.