+5 votes

I want to write an if statement that spans over several lines, how do I do that?

in Engine by (9,316 points)

1 Answer

+12 votes
Best answer

You can use parentheses around the if statement, or backslashes before the newline (which should work anywhere).

Take this script for example:

func _ready():
    if (2 == 2
        and 3 == 3
        and 4 == 4
        and 5 == 5
        and 6 == 6):
            print("The parenthesis way of putting 'if' statements on multiple lines.")

    if 2 == 2 \
        and 3 == 3 \
        and 4 == 4 \
        and 5 == 5 \
        and 6 == 6:
            print("The backslash way of putting 'if' statements on multiple lines.")
by (9,316 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.