How to select and display objects from two dimmensional array Corona SDK ?

First of all hi guys, this is my first post here and I hope not the last one :wink: . Well just recently I have started working on my first application in Corona SDK it is a puzzle game and I am looking for solution how to display a set of images which will be associated with audio file. The images may create words and might be load randomly by the application and here is  my problem begin. I will greatly appreciate it if someone could give me any idea how to resolve my problem

 local puzzles= {
  yes ={ img= “blockY.png”, img =“blockE.png”, img =“blockS.png”,}, --this objects need to be load to create single word
 bed = { img= “blockB.png”, img =“blockE.png”, img =“blockD.png”,},
  } – … or this
  puzzles = display.newImage(puzzles[math.random(#puzzles)]) – how to separate arrays from the block of objects in the array and load them into application?
 puzzles.x = math.random( 115, display.contentHeight - 115 )
 puzzles.y = math.random( 115, display.contentHeight - 115 )

–Button press event
local a_puzzle = function(event)
audio.play(a_letter)
end

puzzle: addEventListener(“tap”, puzzle)
puzzle:addEventListener(“tap”, a_puzzle)

This is my actual working code but in the future I would like to build levels and display words and sound for each tapped letter. I tought about associative array and tables but I am not sure how this could be doable, I hope that someone more experienced would help.

You shouldn’t post this here. It should be under the ‘Lua’ programming category.

Anyway, I would do it in an associative array. Just an idea below…

local puzzles = {} puzzles.yes = { image1 = "image1.jpg", image2 = "image2.jpg", audio1 = "audio1.mp3" } puzzles.no = {....} audio.play( puzzles.yes.audio1 )

Hi Yosu, Thanks for your replay , and yes this post schould be placed somewhere else so I delete this as soon as I sort out my problem. Your idea looks very straightforward however I don’t know how to display properly the objects on the device screen. Althought I don’t get any errors I can’t see anything apart background so I do something wrong. Please help me if you can.

  local puzzleArray = {}
    puzzleArray.yes = {image1 =“blockA.png”, image2 = “blockB.png”, image3 = “blockC.png” }
    puzzleArray.no = {image2 = “blockB.png”, image3 = “blockC.png” }
 
 
 puzzleArray = display.newImage(puzzleArray[math.random(1, 2)])
 puzzleArray = math.random(115, display.contentWidth - 115 )
 puzzleArray = math.random(115, display.contentHeight -115)

You shouldn’t post this here. It should be under the ‘Lua’ programming category.

Anyway, I would do it in an associative array. Just an idea below…

local puzzles = {} puzzles.yes = { image1 = "image1.jpg", image2 = "image2.jpg", audio1 = "audio1.mp3" } puzzles.no = {....} audio.play( puzzles.yes.audio1 )

Hi Yosu, Thanks for your replay , and yes this post schould be placed somewhere else so I delete this as soon as I sort out my problem. Your idea looks very straightforward however I don’t know how to display properly the objects on the device screen. Althought I don’t get any errors I can’t see anything apart background so I do something wrong. Please help me if you can.

  local puzzleArray = {}
    puzzleArray.yes = {image1 =“blockA.png”, image2 = “blockB.png”, image3 = “blockC.png” }
    puzzleArray.no = {image2 = “blockB.png”, image3 = “blockC.png” }
 
 
 puzzleArray = display.newImage(puzzleArray[math.random(1, 2)])
 puzzleArray = math.random(115, display.contentWidth - 115 )
 puzzleArray = math.random(115, display.contentHeight -115)