Expected else after ternary if

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By throwcode

Hi I just received the following error:

res://Scripts/Game.gd:142 - Parse Error: Expected else after ternary if.

The respective code appears like this:

func saucer_destruction(pos):
	var s = expl_saucer.instance()
	var num = Controller.get_numSaucers() - 1

    if num <= 0 :

the “if num <= 0 :” is line 142 and failing with the error message above.

What am I doing wrong, this looks like a standard if statement to me.


Make sure the whole script uses the same indentation (tabs or spaces, don’t mix them) and that there are no special characters inserted as a result of copy-pasting (such as non-breaking spaces).

Calinou | 2019-05-18 14:30

You can get this error by forgetting a parenthesis on a variable just above the if statement. It thinks that you are continuing the var line.

GIngerageous | 2020-01-08 06:22

thanks @Gingerageous : that was my problem :slight_smile:

BakouKai | 2021-04-10 14:11