Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Gribbler on Thu 09/08/2012 16:02:54

Title: using multiple inventory items on object
Post by: Gribbler on Thu 09/08/2012 16:02:54
Hi!

Here's my problem. I wan't the player to say something for one specific inv item, something else for the second, and one general sentence for all other inv items.

My code so far:

Code (AGS) Select

function oBRANCH_UseInv()
{
if (player.ActiveInventory == iHANDSAW) {
      player.Say("You'd have to use your stonger hand.");
}
if (player.ActiveInventory == iHANDSAWRAG) {
      player.Say("Well, alright.");
      player.Walk(123,  108, eBlock);
      object[0].Visible=false;
      player.AddInventory(iBRANCH);
    }

else {
  player.Say("I can't cut it with this.");
}
}




Currently "I can't cut it with this" is displayed as I wanted - when items other than those two specified are used, but it is also displayed after the sentence of the first item. What am I doing wrong?
Title: Re: using multiple inventory items on object
Post by: Crimson Wizard on Thu 09/08/2012 16:33:14
You are missing "else" before second "if".

Code (ags) Select

if (player.ActiveInventory == iHANDSAW) {
      player.Say("You'd have to use your stonger hand.");
}
/* HERE!!---> */ else if (player.ActiveInventory == iHANDSAWRAG) {
      player.Say("Well, alright.");
      player.Walk(123,  108, eBlock);
      object[0].Visible=false;
      player.AddInventory(iBRANCH);
    }
else {
  player.Say("I can't cut it with this.");
}


Basically you structure should be:
Code (ags) Select

if ()
else if()
else if()
.....
else
Title: Re: using multiple inventory items on object
Post by: Gribbler on Thu 09/08/2012 19:03:43
Thank you so much Wizard!