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…

[code]

  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
    [/code] [import]uid: 99780 topic_id: 16939 reply_id: 316939[/import]

[lua]local imageTable = {image1.png, image2.png, image3.png}

local image = display.newImage(imageTable[1])[/lua]

something like that [import]uid: 16142 topic_id: 16939 reply_id: 63521[/import]

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,

?:slight_smile: [import]uid: 3826 topic_id: 16939 reply_id: 63531[/import]

still not working for me.Showing same error.

[code]
Runtime Error
…\main.lua:6:attempt to index local ‘dis’
stack traceback:

>This is what I did…

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

Can you help me now? [import]uid: 99780 topic_id: 16939 reply_id: 63617[/import]

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. [import]uid: 19626 topic_id: 16939 reply_id: 63621[/import]

Thats great …Thanks for the help…You know I have read about the table shuffling…But I bother if this is correct

image={{"image1.png"},{"image2.png"},{"image3.png"}}  
local points = {{x=100,y=200}, {x=100, y=400}, {x=100, y=600}}  
for i=1,#points do  
local select = table.remove(points, math.random(#points))  
local dis=display.newImage("image[i]")  
dis.x=select.x  
dis.y=select.y  
end  

but this is removing the POINTS of the table which I dont want.I want to use these POINTS further in my game So,I want to retain the POINTS .Is this the correct way Or there is any other way to do that?Can anyone help me out please… [import]uid: 99780 topic_id: 16939 reply_id: 63686[/import]

I guess you missed what Rob said and I missed to see that line too myself as your initial issue was with the select.x not working

change line 5 to

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

lose the double quotes!!

where did you get line 4 from??
obviously it reads in plain english

table.remove, why would you want to do that is that is *NOT* what you want to do?

just use your earlier code for line 4

local select=points[math.random(1,#points)]

cheers,

?:slight_smile: [import]uid: 3826 topic_id: 16939 reply_id: 63687[/import]

yes Regarding the image I had figured it out.Anyways thank you for your support.
Regarding POINTS->Doing in the earlier method Overlaps images with the same POINTS ie. one POINTS has the ability to have two or more image which i dont want.I want all the POINTS should have only one image.This can be done by the following

local select = table.remove(points, math.random(#points))  

but Unfortunately it is removing all the POINTS from the table.So I asked if at all is there any other method to do the following…By the way This I got from the forum room.So Could you help me out? [import]uid: 99780 topic_id: 16939 reply_id: 63709[/import]

for i=1,#points do
table.remove(image,i)
end

Hope this helps. [import]uid: 86417 topic_id: 16939 reply_id: 63714[/import]