New images not default

I’m using a world/level select tutorial and one thing it doesn’t cover is how to change the “default” image.
Here’s the code I’m using.

function scene:createScene( event )  
 local group = self.view  
  
 local background = display.newImageRect("background.png",1280,647)  
 group:insert(background)  
 background.x = 240; background.y = 160  
 background:addEventListener("touch",backgroundTouch)  
 group:insert(background)  
 group:insert(buttonGroup)  
 -- create three widget buttons to select the game world   
 for i=1,maxWorlds do  
 worlds[i] = widget.newButton{  
 label="World "..i,  
 default = "worlds.png",  
 id=i,  
 width=128, height=328,  
 onEvent = buttontouch -- event listener function  
 }  
 worlds[i].x = (i\*130) + (i % 1)\*20  
 worlds[i].y = display.contentHeight \* 0.5  
  
 -- If you are using the last publicly available version of Corona, you may  
 -- need to replace the following line with:  
 -- group:insert( worlds[i].view )   
  
 buttonGroup:insert( worlds[i] )  
 end  
  
end  

I’m trying to create 6 unique images for all 6 of the world buttons generated. Any help doing so would be greatly appreciated. [import]uid: 72845 topic_id: 34664 reply_id: 334664[/import]

  1. The image is set right there on line 14. Just change “worlds.png” to whatever the name of the image is.
  2. Since you’re using an iterator, here’s what you do: make a table (first, before you start the button making part)

local images = {} images[1] = "world1.png" images[2] = "world2.png" images[3] = "world3.png" images[4] = "world4.png" images[5] = "world5.png" images[6] = "world6.png"

There are faster ways to write that code, but this lets you use whatever filenames you like!

Then, where you set the default image, use default = images[i],. That way worlds[1] will look for images[1], worlds[2] for images[2], and so on.
[import]uid: 41884 topic_id: 34664 reply_id: 137764[/import]

You sir are amazing! Thank you so much! [import]uid: 72845 topic_id: 34664 reply_id: 137765[/import]

  1. The image is set right there on line 14. Just change “worlds.png” to whatever the name of the image is.
  2. Since you’re using an iterator, here’s what you do: make a table (first, before you start the button making part)

local images = {} images[1] = "world1.png" images[2] = "world2.png" images[3] = "world3.png" images[4] = "world4.png" images[5] = "world5.png" images[6] = "world6.png"

There are faster ways to write that code, but this lets you use whatever filenames you like!

Then, where you set the default image, use default = images[i],. That way worlds[1] will look for images[1], worlds[2] for images[2], and so on.
[import]uid: 41884 topic_id: 34664 reply_id: 137764[/import]

You sir are amazing! Thank you so much! [import]uid: 72845 topic_id: 34664 reply_id: 137765[/import]