Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Pax Animo on Wed 24/08/2022 21:00:35

Title: Get active-inv-id
Post by: Pax Animo on Wed 24/08/2022 21:00:35
Heya,

Brain fog today ???

Is there a way to simply get the ID of a active inventory item so i can achieve something like:

Code (ags) Select
function iBottomlessBag_UseInv()
{
  if (player.ActiveInventory) {
    player.LoseInventory(inventory[ID]);
  }
}


I attempted to make a var such as "get_inv_id" which stores the inventory ID when interactive with it, then using
Code (ags) Select
player.LoseInventory(inventory[get_inv_id]);

But it was messy and didn't feel right
Title: Re: Get active-inv-id
Post by: Crimson Wizard on Wed 24/08/2022 21:03:28
Every fixed object in AGS has ID property:
https://adventuregamestudio.github.io/ags-manual/InventoryItem.html#inventoryitemid

But for above code you don't need it at all, as LoseInventory() function accepts InventoryItem, and ActiveInventory is already InventoryItem.
Code (ags) Select

  if (player.ActiveInventory) {
    player.LoseInventory(player.ActiveInventory);
  }

https://adventuregamestudio.github.io/ags-manual/Character.html#characteractiveinventory
https://adventuregamestudio.github.io/ags-manual/Character.html#characterloseinventory

Today for most cases you don't need IDs, unless you are using them for cross-references with your own custom data.
Title: Re: Get active-inv-id
Post by: Pax Animo on Wed 24/08/2022 21:08:06
Ah ok i knew it had to be something simple, just one of those days...

Thank you.

Edit:
I'll be sure to check out the links you've shared, i do always try to find a solution to a problem via the manuel and other sources, but if i'm at a loss i find it's easier to share the code a give an explanation on what i'm trying to achieve.
Title: Re: Get active-inv-id
Post by: Khris on Thu 25/08/2022 12:39:02
Just for reference, you could've used
Code (ags) Select
  player.LoseInventory(inventory[player.ActiveInventory.ID]); // pretty pointless though