+11 votes

Does GDScript have switch or case statement?

in Engine by (86 points)

2 Answers

–10 votes
Best answer

It's yet to be implemented, as you can see here, under Keywords.

by (1,109 points)
selected by

Is there any eta for when we can expect to see a Select Case statement for GDScript?

I don't think it's in 2.2 milestone, so it may take a long time.

We won't have switch, as there's already "match" in the current git master branch.
So you'll be able to use that in 3.0.

Is it done yet? If not, what alternatives or workarounds could we use?

+18 votes

The GDScript docs have the 'Match' keyword which appears to do the same thing...

A match statement is used to branch execution of a program. It’s the equivalent of the switch statement found in many other languages but offers some additional features.

by (32 points)

Yes, but keep in mind that you need the current git version to use it.
The next stable version that'll have it will be 3.0 :)

Edited -

Hey, "match" "switch" who cares what you call it, right? This is what I need to know. Thanks for clarifying.

How to cascade multiple cases for the same execution?? - so or like leaving out the breaks in Java like languages?


You can also specify multiple patterns separated by a comma. These patterns aren’t allowed to have any bindings in them.

match x:
1, 2, 3:
print("It's 1 - 3")
"Sword", "Splash potion", "Fist":
print("Yep, you've taken damage")


--Also if anyone wants to redirect me to a newer thread thats fine. But this thread always comes up the 10 other times I googled "godot match statement" recently trying to remember how to do it. So I thought it might as well need to be addressed better here, seeing that the google algorithm seems to favor it.

great, yet another language, and yet another way of doing it

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.