How can i make all the letters before the one clicked be returned to the letter box along with the clicked one?

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

I.e. when the e in “real” it’s clicked, a and l also have to return to the letterbox along with e letter.

func _ready():
	for i in range(4):
		for j in range(4):
			var tile:LetterTile = Letter.instance()
			# warning-ignore:return_value_discarded
			tile.connect("tile_clicked", self, "on_tile_clicked", [tile])
			tile.position = Vector2(i * TILESIZE, j * TILESIZE)
			tile.box_position = tile.position

func on_tile_clicked(tile:LetterTile):
	var start_pos = tile.global_position
	if tile.get_parent().name == "LetterBox":
		if word_node_erased == true:
			word_node_erased = false
		tile.global_position = start_pos
		current_word += tile.letter_value
        #This part i mean.
		var tile_position = tile.get_position_in_parent()
		$Tween.interpolate_property(tile,"position", start_pos - $LetterBox.position, tile.box_position,0.2,Tween.TRANS_LINEAR)
		current_word = current_word.substr(0, tile_position) + current_word.substr(tile_position + 1, current_word.length())

enter image description here

:bust_in_silhouette: Reply From: Thomas Karcher

I changed the code in my original Github repository. Here’s what you would need to change in your code:

I basically moved the removal code in an own function, which is called not only for the clicked letter, but for all following letters as well.