godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.05k stars 65 forks source link

Allow IF statements to span multiple lines #9662

Closed Steinbeuge closed 2 weeks ago

Steinbeuge commented 2 weeks ago

Describe the project you are working on

Pretty simple, allow newline in IF statements so they don't span the entire screen when doing something like

func Bounds_Remove():
    if par.global_position.x > x_edge or
    par.global_position.x < -x_edge or
    par.global_position.y < -y_edge or
    par.global_position.y < -y_edge:
        queue_free()

Describe the problem or limitation you are having in your project

Long if statements are hard to read

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Easier to read :)

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

The compiler ignores new lines inside an if statement (between if and : )

If this enhancement will not be used often, can it be worked around with a few lines of script?

It cannot

Is there a reason why this should be core and not an add-on in the asset library?

Can it be an add-on?

RedMser commented 2 weeks ago

Add a backslash to the end of a line to make the compiler ignore newline.

AThousandShips commented 2 weeks ago

This is indeed already possible, see here and here

Steinbeuge commented 1 day ago

This is indeed already possible, see here and here

Thanks for that, didn't know about the parentheses, its extra stuff but does the job. I find the backslash thing odd looking