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