Is it possible to make one character in a string visible?

I’m making a hangman game and I’m trying to figure out how to make only one letter in a string visible. I appreciate the help, I’ve spent an couple hours trying different things but just can’t narrow it down. Here is my code:

This is how I genrated the word using table wordList:
theWord = wordList[mRand]
currentWord = display.newText(theWord, 10, 100, “Times New Roman”, 20)
currentWord.isVisible = false

Here I check to see if there is an A in theWord (which works) the problem comes at the ‘else’ part of the argument… how to make the ‘A’ of currentWord visible?

function gamePlay(event)
local self = event.target
if self.name == “a” then
aa = string.find(theWord, string.upper(self.name))
if aa == nil then
hBody.isVisible = true
else
print("letter "… self.name … " found at position " … aa … " in word " … theWord )
currentWord.isVisible(aa) = true
end
end
end

Thanks!! [import]uid: 170524 topic_id: 30507 reply_id: 330507[/import]

Well the real question is can you make just 1 character in a text object visible? And the answer is no. Instead use a separate text object for each letter. [import]uid: 147305 topic_id: 30507 reply_id: 122238[/import]

Pretty much what budershank said.

Here is a for loop to take a word from random from a table and split it into letters.

Should help you a little :slight_smile:

[lua]-- table of words
words = {“apple”, “cake”, “pie”, “Corona”, “Fried Chicken”}

– random number between 1 & ammount of words
r = math.random(1, #words)
currentword = {}
letterspace = 100

– loop to split letters
for w in string.gmatch(words[r], “.”) do
currentword[#currentword+1] = w
finalText = display.newText(currentword[#currentword], letterspace, 150, native.systemFont, 20)
letterspace = letterspace + 10
end [/lua] [import]uid: 62706 topic_id: 30507 reply_id: 122241[/import]

Thanks for the help! That is what I will do :slight_smile: [import]uid: 170524 topic_id: 30507 reply_id: 122330[/import]

Well the real question is can you make just 1 character in a text object visible? And the answer is no. Instead use a separate text object for each letter. [import]uid: 147305 topic_id: 30507 reply_id: 122238[/import]

Pretty much what budershank said.

Here is a for loop to take a word from random from a table and split it into letters.

Should help you a little :slight_smile:

[lua]-- table of words
words = {“apple”, “cake”, “pie”, “Corona”, “Fried Chicken”}

– random number between 1 & ammount of words
r = math.random(1, #words)
currentword = {}
letterspace = 100

– loop to split letters
for w in string.gmatch(words[r], “.”) do
currentword[#currentword+1] = w
finalText = display.newText(currentword[#currentword], letterspace, 150, native.systemFont, 20)
letterspace = letterspace + 10
end [/lua] [import]uid: 62706 topic_id: 30507 reply_id: 122241[/import]

Thanks for the help! That is what I will do :slight_smile: [import]uid: 170524 topic_id: 30507 reply_id: 122330[/import]