Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Daedelus_helios on Sun 08/03/2009 19:40:33

Title: Problem with IF statement. (SOLVED)
Post by: Daedelus_helios on Sun 08/03/2009 19:40:33
HiI'm really sorry about this, i mean i know its rediculously simple lol but please help:

Ok so i have this:

function hHotspot4_WalkOn()
{
  if(cNick.HasInventory(iJournal)){cNick.ChangeRoom(2, 328, 362);}
  else cNick.Say("I should check this area before i go out there");
  cNick.Walk(500, 300, eBlock, eWalkableAreas);
}

so when he walks on it to leave the room it checks if he has the journal, else he says "" and then walks back.
But even if he has it he walks back and then leaves the room. so is there a way of having the else include two tasks without the walk applying to the if? thanks in advance :)
Title: Re: Problem with IF statement.
Post by: GarageGothic on Sun 08/03/2009 20:14:03
It should be:

function hHotspot4_WalkOn() {
  if (cNick.HasInventory(iJournal)) cNick.ChangeRoom(2, 328, 362);
  else {
    cNick.Say("I should check this area before i go out there");
    cNick.Walk(500, 300, eBlock, eWalkableAreas);
   }
}


Because there are no brackets following your "else" statement it only pertains to the Say line, the walk function runs in both cases.
Title: Re: Problem with IF statement.
Post by: Daedelus_helios on Sun 08/03/2009 20:27:03
Haha thank you so much, i knew it was some silly little error, i thort the curly brace went on the inside of the ";" lol :) thanks again