Godot Version
v4.2.2
Question
Hey guys,
Im new to the godot so excuse my ignorance.
I am trying to create the game where player has to input letters and build a word.
input fields for specific letters are connected to each other. So if user types A in input field other fields are also automatically typed
I also need to check if the user inputed correct letter.
I wrote this code but as you can see it is extremely long and I will need to recreate it for every level which will become almost impossible at some point.
Can anyone help me out, direct me to some documentation or anything really? I’ve been stuck here for days.
Im sorry again and thank you all!
here is the code:
extends CanvasLayer
# Declare variables to store references to the LineEdit nodes for the first group
@onready var input1_group1: LineEdit = $one1
@onready var input2_group1: LineEdit = $one2
@onready var input3_group1: LineEdit = $one3
# Declare variables to store references to the LineEdit nodes for the second group
@onready var input1_group2: LineEdit = $one4
@onready var input2_group2: LineEdit = $one5
@onready var input3_group2: LineEdit = $one6
# Declare variables to store references to the LineEdit nodes for the third group
@onready var input1_group3: LineEdit = $one7
@onready var input2_group3: LineEdit = $one8
@onready var input3_group3: LineEdit = $one9
# Variables to track if conditions are met for each group
var condition_group1_met = false
var condition_group2_met = false
var condition_group3_met = false
func _ready():
# Connect the first group of input fields
input1_group1.connect("text_changed", _on_input_group1_changed)
input2_group1.connect("text_changed", _on_input_group1_changed)
input3_group1.connect("text_changed", _on_input_group1_changed)
# Connect the second group of input fields
input1_group2.connect("text_changed", _on_input_group2_changed)
input2_group2.connect("text_changed", _on_input_group2_changed)
input3_group2.connect("text_changed", _on_input_group2_changed)
# Connect the third group of input fields
input1_group3.connect("text_changed", _on_input_group3_changed)
input2_group3.connect("text_changed", _on_input_group3_changed)
input3_group3.connect("text_changed", _on_input_group3_changed)
func _on_input_group1_changed(new_text: String):
input2_group1.text = new_text
input3_group1.text = new_text
if new_text == "A":
condition_group1_met = true
else:
condition_group1_met = false
check_conditions()
func _on_input_group2_changed(new_text: String):
input1_group2.text = new_text
input3_group2.text = new_text
if new_text == "B":
condition_group2_met = true
else:
condition_group2_met = false
check_conditions()
func _on_input_group3_changed(new_text: String):
input1_group3.text = new_text
input2_group3.text = new_text
if new_text == "C":
condition_group3_met = true
else:
condition_group3_met = false
check_conditions()
func check_conditions():
if condition_group1_met && condition_group2_met && condition_group3_met:
print("Good Job for All Groups")