[SOLVED] help with player.InventoryQuantity

Started by BlueAngel, Sat 10/04/2010 10:23:17

Previous topic - Next topic

BlueAngel

Once again I come to you all with a easy problem that I can’t solve. :-[

In my game the player starts with 3 things. When he has loosed all items the game is over.
But I gets this: Error: type mismatch: cannot convert ‘InventoryItem*’ to ‘int’

This is what I have tried:
Code: ags


function room_RepExec()
if ((player.InventoryQuantity[iRuberband_1]==0)&&(player.InventoryQuantity[iRubberband_2]==0)&&(player.InventoryQuantity[iRubberband_3]==0))
 {
   player.ChangeRoom(8, 0, 0);
 }



When that didn’t work I put in
Code: ags
 
// main global script file

int player.InventoryQuantity[3];


but that didn’t help. :(



Dualnames

You can replace this with:


Code: ags


function room_RepExec()
     if    ((player.HasInventory(iRubberband_1)) &&(player.HasInventory(iRubberband_2)) &&(player.HasInventory(iRubberband_3))) {
           player.ChangeRoom(8, 0, 0);
     }
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

BlueAngel

Quote from: Dualnames on Sat 10/04/2010 10:43:16
You can replace this with:


Code: ags


function room_RepExec()
     if    ((player.HasInventory(iRubberband_1)) &&(player.HasInventory(iRubberband_2)) &&(player.HasInventory(iRubberband_3))) {
           player.ChangeRoom(8, 0, 0);
     }


But isnt that if the player got all things? I want the player to change room when he loose all the 3 items.  ???

Dualnames

Oh, right.
Code: ags


function room_RepExec()
     if    ((player.HasInventory(iRubberband_1)==false) &&(player.HasInventory(iRubberband_2)==false) &&(player.HasInventory(iRubberband_3)==false)) {
           player.ChangeRoom(8, 0, 0);
     }

Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)


Dualnames

Good to know, I misread your post at first, that's why the code I originally posted would word exactly opposite from what you wanted. I suggest you read a little about the function:

Code: ags

bool character.HasInventory(InventoryItem*)


because it's tremendously useful. ;)
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Khris

Just to elaborate a bit:

You can use
  if (!player.HasInventory(iRubberband_1) && ...
(Note the "!", signifying "not")

Alternatively, .InventoryQuantity needs an int as index; you can get that by appending ".ID":
  if ((player.InventoryQuantity[iRubberband_1.ID] == 0) && ...

BlueAngel

Quote from: Khris on Sat 10/04/2010 11:13:16
Just to elaborate a bit:

You can use
  if (!player.HasInventory(iRubberband_1) && ...
(Note the "!", signifying "not")

Alternatively, .InventoryQuantity needs an int as index; you can get that by appending ".ID":
  if ((player.InventoryQuantity[iRubberband_1.ID] == 0) && ...


Aha, so it was the "ID"and the right int that I was missing. Good to know for the future, thanks.

SMF spam blocked by CleanTalk