How to separate two if, else systems

Started by swaz, Sat 11/08/2007 13:14:42

Previous topic - Next topic

swaz

Hi all,
I have a problem separating two if, else systems in "Player enters room, before fadein".
Here's the code:
Code: ags

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.

GarageGothic

#1
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:

Code: ags
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:

Code: ags
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
   }


SMF spam blocked by CleanTalk