Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Capricho on Sun 15/06/2025 21:44:58

Title: I can't combine items in my inventory.
Post by: Capricho on Sun 15/06/2025 21:44:58
Why doesn't my item combining script work?
It always says 'This cannot be combined.'
Sierra-Style Environment
Please advise how to solve the problem.
Thank you

function iVetev_UseInv(InventoryItem *usedItem, CursorMode mode)
{
  if (usedItem == iGumicka)
  {
    player.Say("I conennected a gumicka and a vetev. Now I have a prak.");
    player.InventoryQuantity[iVetev.ID]--;
    player.InventoryQuantity[iGumicka.ID]--;
    player.AddInventory(iPrak);
  }
  else
  {
    player.Say("This cannot be combined.");
  }
}

function iGumicka_UseInv(InventoryItem *usedItem, CursorMode mode)
{
  if (usedItem == iVetev)
  {
    player.Say("I conennected a gumicka and a vetev. Now I have a prak.");
    player.InventoryQuantity[iVetev.ID]--;
    player.InventoryQuantity[iGumicka.ID]--;
    player.AddInventory(iPrak);
  }
  else
  {
    player.Say("This cannot be combined.");
  }
}
Title: Re: I can't combine items in my inventory.
Post by: Crimson Wizard on Sun 15/06/2025 23:43:16
The InventoryItem* parameter in this function is not the used item that player has in "hand", but the item which is being clicked on, so it's other way around.

For checking which item is being used use player.ActiveInventory instead:
https://adventuregamestudio.github.io/ags-manual/Character.html#characteractiveinventory

Code (ags) Select
function iVetev_UseInv(InventoryItem *theItem, CursorMode mode)
{
  if (player.ActiveInventory == iGumicka)

Code (ags) Select
function iGumicka_UseInv(InventoryItem *theItem, CursorMode mode)
{
  if (player.ActiveInventory == iVetev)

On another hand, when you combine items in any order, I may suggest to move the code into a separate function and call from both, in order to reduce code duplication. For example:

Code (ags) Select
function Combine_iGumicka_iVetev()
{
  player.Say("I conennected a gumicka and a vetev. Now I have a prak.");
  player.InventoryQuantity[iVetev.ID]--;
  player.InventoryQuantity[iGumicka.ID]--;
  player.AddInventory(iPrak);
}

function iVetev_UseInv(InventoryItem *theItem, CursorMode mode)
{
  if (player.ActiveInventory == iGumicka)
  {
    Combine_iGumicka_iVetev();
  }
  else
  {
    player.Say("This cannot be combined.");
  }
}

function iGumicka_UseInv(InventoryItem *theItem, CursorMode mode)
{
  if (player.ActiveInventory == iVetev)
  {
    Combine_iGumicka_iVetev();
  }
  else
  {
    player.Say("This cannot be combined.");
  }
}