Problems checking an inventory item Property [solved]

Started by MiteWiseacreLives!, Wed 07/12/2016 23:48:18

Previous topic - Next topic

MiteWiseacreLives!

Sorry if I'm going to clog up the forums today  :-[
I cannot figure why the following gives me an error:
Code: ags
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??

Crimson Wizard

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

if (iInvHat1.GetProperty("IsHat") != 0) // this means "is true"
{
}
if (iInvHat1.GetProperty("IsHat") == 0) // this means "is false"
{
}

MiteWiseacreLives!

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
  InventoryItem *itemToSwap = player.ActiveInventory;  
  
  if (itemToSwap.GetProperty("isGlasses"))
  {
    glasV = itemToSwap.GetProperty("InvenView");
  }


this does not work:
Code: ags

  InventoryItem *itemToSwap = player.ActiveInventory;  
  
  if (itemToSwap.GetProperty("isGlasses"))
    int glasV = itemToSwap.GetProperty("InvenView");  

Crimson Wizard

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.

MiteWiseacreLives!

yes your right. I had to declare it at the top of the function for it to work.

SMF spam blocked by CleanTalk