+6 votes

Is it possible to do something like this? If not does it have planed to support?

velocity = velocity * if (grounded): friction else: 0 
in Engine by (64 points)

AFAIK there is no statement like this, but I this there was/is a discussion about it

If there's something implemented like that, it should be the ternary syntax:

velocity = velocity * friction if grounded else 0

Dear Lord NO! Please, if anything, just implement the ternary operator.
Having the ability to inline full blown if statements ? This is the stuff TDWTF is made of.

2 Answers

+2 votes
Best answer

There's a proposal about this, but no implementation so far. For now you still need to rely on a regular if.

by (797 points)
selected by

Well, thanks you all. Shame, I'm not good at parsing, but i will have a look.

And this has now changed, see below.

+16 votes

According to Godot 2.1.2 release notes it is now available in the ternary syntax and working fine:

GDScript: Ternary operator (a if cond else b)
by (72 points)
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 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 webmaster@godotengine.org with your username.