Can someone tell me why this isn’t working?
local colors = {} colors[1]={} colors[1].flavor= "assets/colorRed.png" colors[2]={} colors[2].flavor= "assets/colorYellow.png" local imageObj = display.newImage( '"'..colors[i].flavor..'"' )
I get this message:
attempt to index field ‘?’ (a nil value)
Thanks!
You’re close, but you don’t need those extra quotes.
for i = 1, 2 do local imageObj = display.newImage( colors[i].flavor ) end
** UPDATED A COUPLE TIMES **
If you don’t really need those sub-tables for anything, you could do this:
local colors = {} colors[1] = "assets/colorRed.png" colors[2] = "assets/colorYellow.png" ... obviously there is some code missing here but I get the gist -- Note: Be sure the following code is in the same scope as your 'local colors' above, or 'colors' will not be visible. print( "Creating image object from this file", colors[i] ) -- Just for debugging sake. local imageObj = display.newImage( colors[i] )
It worked! Much appreciated, roaminggamer!
I tried printing through the terminal and it looks like everything loaded but it loaded too fast. How can this be slowed down to see each image? Do I need to use a transition or a timer? I’m not sure how I’d fit that in.
for i = 1, 2 do print( colors[i].flavor ) local imageObj = display.newImage( colors[i].flavor ) end
Thanks!
You’re close, but you don’t need those extra quotes.
for i = 1, 2 do local imageObj = display.newImage( colors[i].flavor ) end
** UPDATED A COUPLE TIMES **
If you don’t really need those sub-tables for anything, you could do this:
local colors = {} colors[1] = "assets/colorRed.png" colors[2] = "assets/colorYellow.png" ... obviously there is some code missing here but I get the gist -- Note: Be sure the following code is in the same scope as your 'local colors' above, or 'colors' will not be visible. print( "Creating image object from this file", colors[i] ) -- Just for debugging sake. local imageObj = display.newImage( colors[i] )
It worked! Much appreciated, roaminggamer!
I tried printing through the terminal and it looks like everything loaded but it loaded too fast. How can this be slowed down to see each image? Do I need to use a transition or a timer? I’m not sure how I’d fit that in.
for i = 1, 2 do print( colors[i].flavor ) local imageObj = display.newImage( colors[i].flavor ) end
Thanks!