The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

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.

Godot version 3.3.3
in Engine by (255 points)

1 Answer

+2 votes
Best answer

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.

by (736 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.