Godot - Implement switch case with match statement
GDScript code example to implement switch case statement.
GDScript match statement can handle equivalent of switch case.
In match statement, integer "1" and float "1.0" do not match.
var stage = "area1"
match stage:
"area1":
print("area1")
"area2":
print("area2")
_:
print("No Match")
Can also branch process by variable type using match with typeof()
.
var data = []
match typeof(data):
TYPE_FLOAT:
print("float")
TYPE_STRING:
print("text")
TYPE_ARRAY:
print("array")