I can't combine items in my inventory.

Started by Capricho, Yesterday at 21:44:58

Previous topic - Next topic

Capricho

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

Code: ags
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.");
  }
}

Crimson Wizard

#1
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
function iVetev_UseInv(InventoryItem *theItem, CursorMode mode)
{
  if (player.ActiveInventory == iGumicka)

Code: ags
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
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.");
  }
}

SMF spam blocked by CleanTalk