Help!

J

Jamo

Guest
someone please tell me what's wrong with this if statement.

if (localframe >= _totalframes);
{
animationend = true;
localframe -= _totalframes;

}else animationend = false;
 
D

Deleted member 13992

Guest
you have a semicolon where you shouldn't have one, after the condition and before the open bracket. and you are also not bracketing your else properly.

GML:
if (localframe >= _totalframes) {
    animationend = true;
    localframe -= _totalframes;
} else {
    animationend = false;
}
 

Nidoking

Member
you are also not bracketing your else properly.
It's actually okay for a single statement like what's presented here, although I prefer to use brackets as often as possible just to make it more obvious visually. There are a few times when having the statement on the same line without brackets can be a bit more readable, like if the statement is return or exit.
 
D

Deleted member 13992

Guest
It's actually okay for a single statement like what's presented here, although I prefer to use brackets as often as possible just to make it more obvious visually. There are a few times when having the statement on the same line without brackets can be a bit more readable, like if the statement is return or exit.
I stand corrected then. Before learning GML, I programmed for embedded (electronics) in C, which is far pickier about semicolons and brackets. I carried that over to GML because in my mind it's "cleaner". Anything that doesn't follow C guidelines jumps out at me as an error. My mistake in bringing those up.
 

Nidoking

Member
Even in C, you can put a single statement after an if or else without using brackets. It's a guideline, like you said, but not a requirement in either language.
 
Top