Get active-inv-id

Started by Pax Animo, Wed 24/08/2022 21:00:35

Previous topic - Next topic

Pax Animo

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
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
player.LoseInventory(inventory[get_inv_id]);


But it was messy and didn't feel right
Misunderstood

Crimson Wizard

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

  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.

Pax Animo

#2
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.
Misunderstood

Khris

Just for reference, you could've used
Code: ags
  player.LoseInventory(inventory[player.ActiveInventory.ID]); // pretty pointless though

SMF spam blocked by CleanTalk