Thanks Burhan, I went for your first solution because it is seems to be more sensible approach, however I am trying to fit this code and I am still getting funny errors. Basically, I can add leters and display them randomly without any trouble but I don’t know how to assign and play an audio files when the particular randomly selected letter has been tapped by the user. I hope it is clear what I am trying to achieve and here is my code snippet that I am working on.
-- Create table local tablesetup = [[CREATE TABLE IF NOT EXISTS test8 (id INTEGER PRIMARY KEY autoincrement, fL, fA);]] db:exec( tablesetup ) local words = { { fL = "blockA", fA = "blockA" } } -- Insert data into the table for i = 1, #words do local q = [[INSERT INTO test8 VALUES (NULL, ']].. words[i].fL .. [[',']] .. words[i].fA ..[[');]] db:exec(q) end local words = {} local puzzleWord = {} --Select data from table for row in db:nrows("SELECT \* FROM test8 ") do words = {row.fL, row.fA} -- {"blockA","blockB"} end -- Display letters and play audio for randomly displayed letter local wordSpace = 250 -- space between letters local wordXPosition = 150 for i = 1, #words do puzzleWord[i] = display.newImage(words[i]..".png") puzzleWord[i].x = wordXPosition + (i \* wordSpace) puzzleWord[i].y = 200 puzzleWord[i] = audio.loadSound( words[i]..".wav" ) end local playSound = function(event) audio.play(puzzleWord[i].letterSound) end puzzleWord: addEventListener("tap", puzzleWord) puzzleWord: addEventListener("tap", playSound)
Is it possible to make this code running this way where each image and audio file have the same names and different extensions or it would be better off to do this differently ?
Regards
Piotr