Values of the ternary conditional are not mutually compatible

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

Hi,
I’m triying to asign a variable value, that depends on some if/else statement, in one line. I’m trying var offsetX : float = 1 if (sizeX%2 == 0) else 0.5 but the error Values of the ternary conditional are not mutually compatible appears in the debugger. In other script var dir : int = 1 if invert_y else -1 works, now I can’t see the error.

:bust_in_silhouette: Reply From: Lola

Hello,
this is because 1 if not a float and offsetX has to be one. (and it works in the other case because 1 and -1 are both ints)
It seems godot somehow can’t check if the values can be casted or chooses to warn whatsoever.

Doing this removes the warning:

var offsetX: float = 1.0 if (sizeX%2 == 0) else 0.5

I wonder if this should be reported? I find this to be a weird behavior.