Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Tomatoworm on Mon 08/10/2012 18:12:49

Title: Help with "else" statement (SOLVED)
Post by: Tomatoworm on Mon 08/10/2012 18:12:49
Hello,
I have been trying to use the else statement when I use an inventory item on a object ,but I keep getting "unexpected else" error. I'am trying to make it where only one inventory item works.
Here is the script:
function Painting_UseInv()
{
  if (cBert.ActiveInventory == iPscraper)
  cBert.Walk(445, 218, eBlock, eWalkableAreas);
  cBert.FaceObject(Painting);
  Painting.Visible = false;
  PaintingSide.Visible = true;
  RemoveWalkableArea(4);
}
  else{
  cBert.Walk(445, 218, eBlock, eWalkableAreas);
  Display("This won't work");
}

Has anyone else had this problem?
Title: Re: Help with "else" statement
Post by: geork on Mon 08/10/2012 18:25:53
Put a bracket behind the "if" clause, and remember to finish the whole function with a bracket
Code (AGS) Select

function Painting_UseInv()
{
  if (cBert.ActiveInventory == iPscraper){ //this is where the bracket was missing
  //stuff
  }
  else{
  //other stuff
  }
}//to close the function


That should do it :)
Title: Re: Help with "else" statement
Post by: Tomatoworm on Mon 08/10/2012 18:38:36
That was it!I keep on forgetting about the closing braces. Thank for for you reply! :-D