Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: COMMANDOS2 on Mon 31/10/2022 06:16:32

Title: Help Combining
Post by: COMMANDOS2 on Mon 31/10/2022 06:16:32
Hello, i need so much help, please, i'm burning my brain trying to discover how :confused:  but i can't
i'm making my first game in the latest version of AGS and i got some problems combining items each other in the inventory, here is my work:

Spoiler
function iVault_UseInv()
{
        if (player.ActiveInventory == iKeys)
        player.LoseInventory(iVault);
        player.AddInventory(iVault1open);
        player.AddInventory(iLotofcash);
        cRoger.Say("YEAH! I'M RICH NOW!");
}
[close]
function iVault_UseInv()
{
        if (player.ActiveInventory == iKeys)
        player.LoseInventory(iVault);
        player.AddInventory(iVault1open);
        player.AddInventory(iLotofcash);
        cRoger.Say("YEAH! I'M RICH NOW!");
}



But here is the problem. :~(
if i pick another item (like a "iWallet"), i can use it on the iVault to open it too, i'm sorry if this is not the thread, but i need some help to make this work, Thanks!
Title: Re: Help Combining
Post by: Nahuel on Mon 31/10/2022 06:34:36
Hey @COMMANDOS2 you are totally forgetting the { }

function iVault_UseInv()
{
        if (player.ActiveInventory == iKeys)
        {
          player.LoseInventory(iVault);
          player.AddInventory(iVault1open);
          player.AddInventory(iLotofcash);
          cRoger.Say("YEAH! I'M RICH NOW!");
        }
}

[EDIT]
You can also read https://adventuregamestudio.github.io/ags-manual/ScriptingTutorial.html that is an excellent source.
Title: Re: Help Combining
Post by: COMMANDOS2 on Mon 31/10/2022 06:40:57
Quote from: Nahuel on Mon 31/10/2022 06:34:36Hey @COMMANDOS2 you are totally forgetting the { }

function iVault_UseInv()
{
        if (player.ActiveInventory == iKeys)
        {
          player.LoseInventory(iVault);
          player.AddInventory(iVault1open);
          player.AddInventory(iLotofcash);
          cRoger.Say("YEAH! I'M RICH NOW!");
        }
}


THIS WORK!
now how can i do for add an "else" like if i'm using another item, "cRoger.Say" "nope, this doesn't wotk"?
i'm so grateful with your help, that i'm gonna cry, really thanks!!
Title: Re: Help Combining
Post by: Nahuel on Mon 31/10/2022 07:11:00
Simply you add the else with { }

function iVault_UseInv()
{
        if (player.ActiveInventory == iKeys)
        {
          player.LoseInventory(iVault);
          player.AddInventory(iVault1open);
          player.AddInventory(iLotofcash);
          cRoger.Say("YEAH! I'M RICH NOW!");
        }
        else
        {
          // the rest
        }
}
Title: Re: Help Combining
Post by: Khris on Mon 31/10/2022 07:31:22
See also here:
https://adventuregamestudio.github.io/ags-manual/ScriptKeywords.html#if-else-statements