Mittens 2018 will be in Boston this September. There are three spaces left, so check out the thread for details!

Author Topic: Inventory Item At Index  (Read 237 times)

Vincent

  • Jump back into the pond
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
Inventory Item At Index
« on: 30 Nov 2017, 22:28 »
Good evening to all AGSer folks!

I really hope that you're not tired for my noob questions.
The thing that I am going to ask you today it seems much simple to do, but at the moment I really can't find a good solution to it. So, I need to add an inventory item to a specific index, more specifically, where it was a certain item before to removing it. Well, into the manual I could find something like this: readonly InventoryItem* InvWindow.ItemAtIndex[]; but how I could use this for my purpose? How do you check where it is exactly a certain item into the inventory window?

Khris

    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
    • Khris worked on a game that was nominated for an AGS Award!
Re: Inventory Item At Index
« Reply #1 on: 30 Nov 2017, 23:27 »
Something like this should work:

Code: Adventure Game Studio
  1.   int index;
  2.   for (int i = 0; i < invWindow.ItemCount; i++) {
  3.     if (invWindow.ItemAtIndex[i] == iOldItem) index = i;
  4.   }
  5.   player.LoseInventory(iOldItem);
  6.   player.AddInventory(iNewItem, index);

Vincent

  • Jump back into the pond
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
Re: Inventory Item At Index
« Reply #2 on: 30 Nov 2017, 23:40 »
Awesome Khris!

Thank you very much for your kind help.
I have to leave my workstation for now but I will let you know as soon as possible on tomorrow.
I really can't wait to test this!
Thank you very much again and have a good night.

Vincent

  • Jump back into the pond
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
Re: Inventory Item At Index
« Reply #3 on: 01 Dec 2017, 09:38 »
I had no doubts about it but it worked exceptionally fine! Thank you very much! :)