Tip: JavaScript if/else Bracket Rules

Another installment in my “tips I wish I had known an hour or more ago”.

It seems that Unity’s JavaScript doesn’t like using an if/else with the no-brackets/single-command version for the if and the bracketed/multiple-command version for the else. For example:

if (something == true)
	print("something is true!");
else {
	var message = "something is false";
	print(message + "???");
}

The lesson of the day is stick to either brackets or no brackets for each whole if/ifelse/else block.

probably a good idea to do it around the if statement as well

if () {
} else {
}