App Needs Tap/Touch and Keep Value

Abstract: alphabet app to do spelling check against dictionary, when done.

For example: if you tap on “d.png” “o.png” “g.png” the image disappears on the screen but the value should be kept, “dog” in another corner, when user click on “spelling check” to check against dictionary.

Issue: I am stuck on passing the random display of the image, translate to alphabet and touch to disappear but to keep value for spell check.

All suggestions and feedbacks are welcome, thank you.

-- define image and alphabets  
local myAlphabet =  
{  
 "a.png",  
 "b.png",  
 "c.png",  
 "d.png",  
 "e.png",  
 "f.png",  
 "g.png",  
 "h.png",  
 "i.png",  
 "j.png",  
 "k.png",  
 "l.png",  
 "m.png",  
 "n.png",  
 "o.png",  
 "p.png",  
 "q.png",  
 "r.png",  
 "s.png",  
 "t.png",  
 "u.png",  
 "v.png",  
 "w.png",  
 "x.png",  
 "y.png",  
 "z.png",  
}  
textX = 10   
  
function selectRandom ()  
 local rand = math.random(#myAlphabet)  
 local aFile = myAlphabet[rand]  
 -- display X instead of Y, hence textX  
 local ni = display.newImage(aFile, textX, 60)  
 textX = 25 + textX  
 table.remove(myAlphabet, rand)  
end  
-- the number of times text dislay on screen, for tap/touch.  
selectRandom()  
selectRandom()  
selectRandom()  
selectRandom()  
selectRandom()  
selectRandom()  
selectRandom()  
selectRandom()  
selectRandom()  
selectRandom()  
selectRandom()  
selectRandom()  
  

[import]uid: 21304 topic_id: 5856 reply_id: 305856[/import]

[lua]function makeAlphabet(letters)
– convert letter to alphabet table ie “abcde” => {“a”,“b”,“c”,“d”,“e”}
local alphabet = {}
letters:gsub("([^*])", function© table.insert(alphabet, c) end)
return alphabet
end

myLetters = “abcdefghijklmnopqrstuvwxyz”
myAlphabet = makeAlphabet(myLetters)

local word = “”

textX = 10

function selectRandom ()
local rand = math.random(#myAlphabet)
local letter = myAlphabet[rand]
local aFile = letter … “.png”
– display X instead of Y, hence textX
local ni = display.newImage(aFile, textX, 60)
textX = 25 + textX
table.remove(myAlphabet, rand)
return letter
end

– the number of times text dislay on screen, for tap/touch.
for n=1, 5, 1 do
word = word … selectRandom()
end
print(word)[/lua] [import]uid: 6645 topic_id: 5856 reply_id: 20046[/import]

Thank you for the quick response. Your code makes me realize I need more reading of Lua and probably need a basic flow chart of some sort. I missed the basics of function calls.

Hopping on over to lua.org to do some reading and ordering the Programming in Lua (2nd edition) for more reading.
[import]uid: 21304 topic_id: 5856 reply_id: 20076[/import]