why does this table setup doesn't work?

  here is a simple table

tableForImages = {} for c = 1, 10 do tableForImages[c] = "hello" tableForImages[c].status = "hi" end

here is the error string:

attempt to index field ‘?’ (a string value)

In the line **tableForImages[c] = “hello” **you make tableForImages[c] a string, “hello”.

Then in the next line you are trying to treat this string as a table. So you need to change it up a bit.

Like this for example:

[lua]

tableForImages = {}

for c = 1, 10 do

   tableForImages[c] = {}

   tableForImages[c].something = “hello”
   tableForImages[c].status = “hi”

end

[/lua]

Oh I see, thanks :slight_smile:

btw, If I use it like this

testImage[i] = display.newImage("whateverimage.png, params) testImage[i].status = "Open Me"

it works, or whatever display object I use

That’s because display.newImage() returns a table, which is similar to Jon’s setting it to an empty table with his  " = {} " assignment.

Rob

Oh okay thanks

In the line **tableForImages[c] = “hello” **you make tableForImages[c] a string, “hello”.

Then in the next line you are trying to treat this string as a table. So you need to change it up a bit.

Like this for example:

[lua]

tableForImages = {}

for c = 1, 10 do

   tableForImages[c] = {}

   tableForImages[c].something = “hello”
   tableForImages[c].status = “hi”

end

[/lua]

Oh I see, thanks :slight_smile:

btw, If I use it like this

testImage[i] = display.newImage("whateverimage.png, params) testImage[i].status = "Open Me"

it works, or whatever display object I use

That’s because display.newImage() returns a table, which is similar to Jon’s setting it to an empty table with his  " = {} " assignment.

Rob

Oh okay thanks