So you can do this all with code. Probably what I would do, is use get_nodes_in_group() for a selected word (say "water") and then sort that list by come criteria. For example, if the words all start at the top and move down at a uniform speed, you can use the y position. So put all the words under a single Node2D (say it is called "Words") and then use get_children() to get the children and then sort those.
extends Node2D
func _ready():
var lowest_word = get_lowest_word()
print(lowest_word.name)
func get_lowest_word():
var words = get_node("Words")
var all_words = words.get_children()
all_words.sort_custom(Sorter, "sort_y")
return all_words[0]
class Sorter:
static func sort_y(a, b):
return a.position.y > b.position.y
If you want to do it based on when they are created, then modify the code to save the Unix timestamp when you spawn the word, and then add a sort function to compare that (rather than the y value). You can get the time with OS.get_unix_time().
extends Node2D
func _ready():
var test = 10
var words = get_node("Words").get_children()
for word in words:
word.time = OS.get_unix_time() + test
test += 10
var oldest_word = get_oldest_word()
print(oldest_word.name)
func get_oldest_word():
var words = get_node("Words")
var all_words = words.get_children()
all_words.sort_custom(Sorter, "sort_time")
return all_words[0]
class Sorter:
static func sort_time(a, b):
return a.time < b.time