• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Unexpected symbol in word 'else'?

C

Charliebailey03

Guest
I'm not very skilled at writing code as you can probably tell.
Can anyone say what the problem is with this?
[Just to say, it's in the Step Event]

///Distance to sofa with views
if distance_to_object(ob_sofa) < 8 ;
{
view_visible[0] = false
view_visible[1] = true
}
else
{
view_visible[0] = true
view_visible[1] = false
}
 

TheouAegis

Member
A semi-colon ends a statement or expression.

if a //expression
b //statement

if a { //expression
b //statement
c //statement
}

if a; //expression + statement, the rest of the code is now outside of the if-conditional
b //this will run all the time now

if a; //expression + statement, the resf of the code is now outside of the if-conditional
{
b //this will run all the time now
c this will run all the time now
}


Note that in Game Maker you do not need a semicolon 99% of the time. The only time you need a semicolon is at the end of a variable declaration.

var a; a=0

or

var a = 0; //this works in GM:Studio, but not older versions of GM
 
C

Charliebailey03

Guest
A semi-colon ends a statement or expression.

if a //expression
b //statement

if a { //expression
b //statement
c //statement
}

if a; //expression + statement, the rest of the code is now outside of the if-conditional
b //this will run all the time now

if a; //expression + statement, the resf of the code is now outside of the if-conditional
{
b //this will run all the time now
c this will run all the time now
}


Note that in Game Maker you do not need a semicolon 99% of the time. The only time you need a semicolon is at the end of a variable declaration.

var a; a=0

or

var a = 0; //this works in GM:Studio, but not older versions of GM
Remove the semi colon after the 8 I think.
Thanks for the help! However, I tried it and it works, but when I leave the room and come back again it doesn't. Any thoughts on this?
 

TheouAegis

Member
if it works and then later doesn't work, then your error is somewhere else. Considering you made one rookie error, odds are there is another rookie error somewhere else in your project.
 
Top