Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Da_Elf on Fri 17/11/2006 21:15:17

Title: Inventory quantity
Post by: Da_Elf on Fri 17/11/2006 21:15:17
somethings wrong with my script here
if (player.ID == 2) {
Ã,  if (GetGraphicalVariable("sack") == 0) {
Ã,  Ã, if (player.InventoryQuantity >3) {
Ã,  Ã,  Ã, Display("You only have two hands to carry things");
Ã,  Ã,  Ã, Display("It would be easier if you had something to carry things in.");
Ã,  Ã, }
Ã,  Ã, else {
Ã,  Ã, player.AddInventory(inventory[8]);
Ã,  Ã, object[1].Visible = false;
Ã,  Ã, SetGraphicalVariable("GETMONEY",Ã,  50);
}
}
else {
Ã,  Ã, player.AddInventory(inventory[8]);
Ã,  Ã, object[1].Visible = false;
Ã,  Ã, SetGraphicalVariable("GETMONEY",Ã,  50);
}

}
else {
Ã,  Ã, DisplayMessage(4);
}
}


how am i supposed to use the inventory quantity. its giving me an error.
basically what i want is that you can not have more then 3 items in the inventory unless you have picked up a sack
Title: Re: Inventory quantity
Post by: Ashen on Fri 17/11/2006 21:26:54
You should always post the error message you get, but I think I see the problem here anyway.

Read the Manual (http://www.adventuregamestudio.co.uk/manual/Character.InventoryQuantity.htm):
Quote
Gets/sets the quantity of the specified inventory item that the character currently has. The array index is the inventory item number, from the Inventory pane in the editor.

You have to tell it which Inventory item you want to check the quantity of, e.g.:

if (player.InventoryQuantity[iKey.ID] > 3) { // i.e. player has more than 3 keys
  // Do Stuff
}


It doesn't check the total number of ALL items in the character's inventory - which seems to be what you want?
There's no easy way to check that. You can either use a variable to track it and add to that everytime you give the player an item, or use a while loop to check every possible item each time, e.g. (untested):

int Temp=1, Count; // Temp = 1, because items start from 1 not 0
while (Temp <= Game.InventoryItemCount) {
  Count += player.InventoryQuantity[Temp]; // Add the ammount of the current item the player has
  Temp ++: // Move on to next item
}

  if (Check > 3) {
    //Do stuff
  }

Title: Re: Inventory quantity
Post by: Da_Elf on Fri 17/11/2006 21:29:54
ah ha. yes. smart. ill just tag on a variable for the items i have and increase it every time i get an item then i can use this variable THANK YOU!!!