Hi all,
Imagine I have:
var hiddenWord = "BEAUTIFUL"
I also have an array:
var charactersPressed = ["A", "E", "I", "O", "U"]
I have another variable as such:
var displayWord = ""
I want to work through hiddenWord
letter by letter and if I come across a letter that lives in charactersPressed
I want to push that character into displayWord
. If the letters don't match I want to push an X
into displayWord
.
So with the above example, displayWord
would look like "XEAUXIXUX"
I've started with this kind of logic (below), but it's beating me and I feel I'm making it harder than I need to, hence asking here.
func showWord(word):
displayWord = "" #reset to nothing so we can rebuild it
if not word.empty(): #if word is actually present
var length = word.length() #Might not be needed.
for letter in hiddenWord:
for arrayLetter in charactersPressed:
if letter == arrayLetter:
displayWord.[SOME_KINDOF_ID] = letter #how do I do this?
else:
displayWord.[SOME_KINDOF_ID] = letter #how do I do this?
get_node("wordLabel").set_text(displayWord)
EDIT: I know that the above loops will not produce the desired result. They will create a VERY long displayWord. That's my next challenge. For now the big things is changing the displayWord character in a specific spot which is the first part of the puzzle for me.