Material Box

Material Box

WEB Design & Material Images

Godot - Implement switch case with match statement

Godot

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")

Godot

TitleGodot - Implement switch case with match statement

CategoryGodot

Created

Update

AuthorYousuke.U