Hello,
I just started on my first AGS game (using AGS 3.1.1) a few days ago and already ran into trouble:
How can I find out, which index/position an InventoryItem has in the inventory?
I have a lot of combining and swapping in the inventory going on, so I really need a way to figure that out. Right now, thats my approach - and its obviously wrong:
Code: ags
If you wonder, why exactly that does not work for me: I quite often have the case of several identical items in the inventory. My getIndex-Function will always return the first of those, but this is not necessarily the one, the user clicked on.
This probably is quite a dumb question, but any help would be greatly appreciated. :-)
I just started on my first AGS game (using AGS 3.1.1) a few days ago and already ran into trouble:
How can I find out, which index/position an InventoryItem has in the inventory?
I have a lot of combining and swapping in the inventory going on, so I really need a way to figure that out. Right now, thats my approach - and its obviously wrong:
function getIndex(InventoryItem* item) {
int i=0;
while(i<(InventoryWindow1.ItemCount)) {
if(InventoryWindow1.ItemAtIndex[i]==item) return i+1;
i++;
}
return 1;
}
// Some simplified test code: Taking an item (testItem) apart, resulting in two new items (testItem2 and testItem3)
// This happens, when the user is doing a certain action on "testItem"
int index = getIndex(testItem);
player.AddInventory(testItem2, index);
player.AddInventory(testItem3, index+1);
player.LoseInventory(testItem);
If you wonder, why exactly that does not work for me: I quite often have the case of several identical items in the inventory. My getIndex-Function will always return the first of those, but this is not necessarily the one, the user clicked on.
This probably is quite a dumb question, but any help would be greatly appreciated. :-)