using multiple inventory items on object

Started by Gribbler, Thu 09/08/2012 16:02:54

Previous topic - Next topic

Gribbler

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

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?

Crimson Wizard

You are missing "else" before second "if".

Code: ags

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

if ()
else if()
else if()
.....
else

Gribbler


SMF spam blocked by CleanTalk