Godot Version
4.3
Question
I have an array of labels. Is it possible to use the has()
function to determine if there is a label matching a particular text? Or will I have to use a different type like a dictionary.
4.3
I have an array of labels. Is it possible to use the has()
function to determine if there is a label matching a particular text? Or will I have to use a different type like a dictionary.
The has() function used to determine the child of a node not text, you can use loop and if statement for it.
var matched_label:Label = label_array.filter(func(l:Label):return l.text == "text I am looking for")
Small correction, @sancho2: filter()
returns an Array
If you mean an array such as nodes with labels, yes it will work
var lbl:Array=[$TextureRect/Label, $Label2, $Button2]
if lbl.has($TextureRect/Label):
pass
Also this will work win has()
and in
:
var lbl:Array=["abc","xyz",1,2]
if lbl.has("xyz"):
pass
if 1 in lbl:
pass
Thanks everyone for the help. I ended up just using the filter function to narrow it down to the one label Iām interested in.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.