Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: nightmarer on Thu 08/04/2021 22:42:52

Title: Array length
Post by: nightmarer on Thu 08/04/2021 22:42:52
Hello.

I would like to transfer all the items from one character to another character which is going to be the player.ç
I was trying to create a for to transfer them from one to another, but I don't know which property gets the number of that array

Code (ags) Select
  for(i = 1, i < CharacterA.InventoryQuantity[].length(), i++) {
    CharacterB.InventoryQuantity[i] = CharacterA.InventoryQuantity[i];
  }


Thank you.
Title: Re: Array length
Post by: Crimson Wizard on Thu 08/04/2021 23:10:47
It's Game.InventoryItemCount in that case.

In general, AGS script does not support getting length from arrays themselves, so there must be separate property or constant for built-in arrays, and length stored in a separate variable for user arrays.
Title: Re: Array length
Post by: nightmarer on Fri 09/04/2021 10:43:19
Thank you. If someone needs something similar this is how it worked for me.
Code (ags) Select

int i;
for(i = 1; i < Game.InventoryItemCount; i++) {
   CharacterB.InventoryQuantity[i] = CharacterA.InventoryQuantity[i];
}
UpdateInventory();