0

I have been working on a grid based game, similar to wordle, that will change the label of each grid space to be equal to user input. I figured out how to change a label based on user input, but I am not sure how I can set all labels to be null on ready. I know I could just have each label empty through the sidebar, but I would like to be able to clear them with code for reseting the game.

The following is what I have tried, but this only lets me edit the specified label. I thought maybe I could use some system to edit children of the grid?

func _input(event):
    if event is InputEventKey and event.is_pressed():
        var key_text = OS.get_keycode_string(event.get_physical_keycode_with_modifiers())
        print(key_text)
        set_letter(key_text)

func set_letter(letter: String):
    $VBoxContainer/MiddleHBox/MidVBox/GridContainer/Space1/Label.text = letter
Adriaan
  • 17,741
  • 7
  • 42
  • 75

1 Answers1

0

To update the labels of the children of GridContainer, you will need to iterate through each one of the children.

To do that you can use a for loop:

func set_all_labels(letter: String):
    var children = $VBoxContainer/MiddleHBox/MidVBox/GridContainer.getChildren()
    for child in children:
        child.get_node('Label').text = letter
Cassiano
  • 71
  • 1
  • 3