Help on tables, and showing pictures

Hi everyone…

I have this function and it works fine.

local function findingNotes()         local notesPictures = {"images/quarterNoteUp.png","images/wholeNote.png", "images/trebleClef.png"}         local notes = display.newImage(notesPictures[math.random (#notesPictures)])         notes.x = 400; notes.y = 700                     return true end

I press a button and I get a random note image, so every time I re-launch the app I get a new note, it’s great!

The problem is, when I press the button again, the first image doesn’t remove itself. so now I have 2 images

or 3 or four.

I tried this

local function buttonGameHandler()         notes = nil;         local notesPictures = {"images/quarterNoteUp.png","images/wholeNote.png", "images/trebleClef.png"}         local notes = display.newImage(notesPictures[math.random (#notesPictures)])         notes.x = 400; notes.y = 700                     return true end

and it did note work –

I tried this one too

local function buttonGameHandler()         display.remove(notes)         local notesPictures = {"images/quarterNoteUp.png","images/wholeNote.png", "images/trebleClef.png"}         local notes = display.newImage(notesPictures[math.random (#notesPictures)])         notes.x = 400; notes.y = 700                     return true end

And didn’t work…

I’m trying to use the logic, but I don’t get it.

Please I need some help

Thanks

Try this:

local notes -- at the top of your code local function buttonGameHandler() display.remove(notes) local notesPictures = {"images/quarterNoteUp.png","images/wholeNote.png", "images/trebleClef.png"} notes = display.newImage(notesPictures[math.random (#notesPictures)]) notes.x = 400; notes.y = 700 return true end

Thank you very much JonPM, you save my day. I still need to learn a lot more

it’s incredible how one little simple thing, and I was going crazy.

programming requires a lot of details. But I’m learning a lot.

One more thing for this same idea. I can show a different image every time.

I want to use the “if” statement to make something happen. something like this


if --the picture in notesPicture table is 1 do

        transition.to(anotherImage, (time=1000, x=34, y=120)

else

      show this button

end


This is the idea. And lso if I have 20 pictures in the table, how do I do that.

if pict == 1 do

    this

if pict == 2 do

   something

if pict == 3 do

  bla bla bla

is it like that?

Victor

Try this:

local notes -- at the top of your code local function buttonGameHandler() display.remove(notes) local notesPictures = {"images/quarterNoteUp.png","images/wholeNote.png", "images/trebleClef.png"} notes = display.newImage(notesPictures[math.random (#notesPictures)]) notes.x = 400; notes.y = 700 return true end

Thank you very much JonPM, you save my day. I still need to learn a lot more

it’s incredible how one little simple thing, and I was going crazy.

programming requires a lot of details. But I’m learning a lot.

One more thing for this same idea. I can show a different image every time.

I want to use the “if” statement to make something happen. something like this


if --the picture in notesPicture table is 1 do

        transition.to(anotherImage, (time=1000, x=34, y=120)

else

      show this button

end


This is the idea. And lso if I have 20 pictures in the table, how do I do that.

if pict == 1 do

    this

if pict == 2 do

   something

if pict == 3 do

  bla bla bla

is it like that?

Victor