match array difficulty

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By todog


New to Godot

Trying to use the “match array” feature but can’t get a match as expected. Ordinary matching works for me.

My code:

enter code here
var s = $PanelCommand/LineEditCommand.text.split(' ', true, 2)
match s:
		prints("no command")
	["go", var destination]:
		prints("command go to ", destination)
		prints("command go")
		prints("command stop")
		prints("no match")

Output with various values:

[go, 1]
no match

no match

no match

no match

I see that split returns PoolStringArray but would have thought match would work with that.

Any clues?

:bust_in_silhouette: Reply From: hilfazer

Match is not doing implicit type conversions. It was done “to prevent errors”

Cast s to Array:

match Array(s):

great. that works. thanks.

todog | 2019-01-01 10:43