Is there any way to identify words from a label (or array) within my TextEdit Text?

Hello, I’m a relatively new user to Godot and am currently coding a game that requires a word identification system. My current code is listed down below. I have ‘Meow’ as a place holder currently. This code works, but I’m unsure on if I could replace ‘Meow’ with the words within my array (which are currently a series of letters from A-G but i will be replacing them with full words later)

func _on_tutton_pressed() -> void:
	text_edit.editable = false
	if  $TextEdit.text.contains('Meow'):
		print("score")

this is godot 4.6.

Use a for loop to iterate over your array of words and do the same check as you did with “Meow” on each item of the array.

Something like this would run the same check against every entry:

@export var words: Array[String] = ["A", "B", "C"]

func _on_tutton_pressed() -> void:
	text_edit.editable = false
	for word in words:
		if text_edit.text.contains(word):
			print("score ", word)

One thing to keep in mind, contains is a substring check. With single letters in the array right now, an “A” counts as a hit inside any word the player typed, and once you swap in real words, “cat” would still match inside “catalog”.

If you want a word to only count when it’s typed on its own, split the text first and check the pieces:

var typed := text_edit.text.to_lower().split(" ", false)
for word in words:
	if typed.has(word.to_lower()):
		print("score ", word)

That version splits on spaces, so something like “cat.” with punctuation on it wouldn’t match.