Does GDScript have switch or case statement?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Chr_
:warning: Old Version Published before Godot 3 was released.

Does GDScript have switch or case statement?

:bust_in_silhouette: Reply From: mateusak

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

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

Burningfeetman | 2016-08-20 11:37

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

mateusak | 2016-08-21 03:54

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.

Hinsbart | 2017-02-16 15:04

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

C:\Flavius | 2018-04-25 19:32

:bust_in_silhouette: Reply From: James Grimwood

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.

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 :slight_smile:

Hinsbart | 2017-02-16 15:05

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?

EDIT: JUST DUG DEEPER AND ANSWERED MY OWN QUESTION>>>>>

"
Multipatterns:
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.

Armslice | 2019-05-28 07:42

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

phil1234 | 2021-05-19 17:51