Using Tables

how to use table to display the images So that it can be displayed.Is this the wright way to do that coz I am getting an error on line no 6.Discard the digits in the Program..

1
2
3
4
5
6
7
8
1. image={{"image1.png"},{"image2.png"},{"image3.png"}}
2. local points={{100,200},{100,400},{100,600}}
3. for i=1,#points do
4. local select=points[math.random(#points)]
5. dis=display.newImage("image[i]")
6. dis.x=select.x
7. dis.y=select.y
8. end

1
2
3
local imageTable = {image1.png, image2.png, image3.png}
 
local image = display.newImage(imageTable[1])

you are getting an error because in your table, you do not have an element called x that you are trying to refer to.

in line 2, use

local points = {{x=100,y=200}, {x=100, y=400}, {x=100, y=600}}

then it will work for you

cheers,

?:)

still not working for me.Showing same error.

1
2
3
Runtime Error
...\main.lua:6:attempt to index local 'dis'<a nil value>
stack traceback:

local dis=display.newImage("image[i]")

should be:

local dis=display.newImage(image[i])

With the quotes you are trying to pass a string to display.newImage that contains the characters: i, m, a, g, e, [, i, ] instead of the value stored in image[i]

dis can't find a file name called "image[i]" and returns nil and when you try to set the X value on it, dis is nil, which causes your error.

views:1553 update:2011/10/28 9:34:19
corona forums © 2003-2011