Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Topics - Beefy

#1
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

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. :-)
SMF spam blocked by CleanTalk