Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: swaz on Sat 11/08/2007 13:14:42

Title: How to separate two if, else systems
Post by: swaz on Sat 11/08/2007 13:14:42
Hi all,
I have a problem separating two if, else systems in "Player enters room, before fadein".
Here's the code:

if (GetGlobalInt(1) == 0){
object[0].Visible = false;}
else object[0].Visible = true;}
if (GetGlobalInt(2) == 0);{
object[1].Visible = true;}
else
object[1].Visible = false;}


Running this script i get the error "unexpected if" and the cursor goes on the second if.
I've tried all but I can't use the second if.
Suggestions?
Thanks.
Title: Re: How to separate two if, else systems
Post by: GarageGothic on Sat 11/08/2007 13:21:00
The problem is your use of end brackets after the "else..." lines. You're trying to close a bracket which hasn't been started. Remember that the number of { and } brackets should always be the same:

if (GetGlobalInt(1) == 0) object[0].Visible = false; //no need for the brackets really, as you only run one line
else object[0].Visible = true; //no end bracket here
if (GetGlobalInt(2) == 0) object[1].Visible = true;  //no need for the brackets really, as you only run one line. There was also a ";" after the if statement which shouldn't be there.
else object[1].Visible = false;//no end bracket here either


If you needed to run more than one line of code in each if/else statement, you could use brackets like so:

if (GetGlobalInt(1) == 0) {
   object[0].Visible = false;
   //blah blah blah, more stuff here
   }
else {
   object[0].Visible = true; //no end bracket here
   //blah blah blah, even more stuff here
   }
Title: Re: How to separate two if, else systems
Post by: swaz on Sun 12/08/2007 01:33:25
Thank you!