+4 votes

Does GDScript have switch or case statement?

asked Aug 12, 2016 in Engine by Chr_ (64 points)

2 Answers

–1 vote
Best answer

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

answered Aug 12, 2016 by mateusak (1,023 points)
selected Aug 13, 2016 by Chr_

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?

+6 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.

answered Feb 16, 2017 by James Grimwood (26 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 :)

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.