match array difficulty

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

Hi,

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)
prints(s)
match s:
	[]:
		prints("no command")
	["go", var destination]:
		prints("command go to ", destination)
	["go"]:
		prints("command go")
	["stop"]:
		prints("command stop")
	_:
		prints("no match")

Output with various values:

[go, 1]
no match

[go]
no match

[stop]
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