Inventory quantity

Started by Da_Elf, Fri 17/11/2006 21:15:17

Previous topic - Next topic

Da_Elf

somethings wrong with my script here
Code: ags
 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

Ashen

#1
You should always post the error message you get, but I think I see the problem here anyway.

Read the Manual:
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.:
Code: ags

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):
Code: ags

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
  }

I know what you're thinking ... Don't think that.

Da_Elf

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!!!

SMF spam blocked by CleanTalk