Help with data structures

[lua]local t1 = {

{ x=310, y=178 },
{ x=340, y=220 },
{ x=340, y=270 },
{ x=305, y=312 },
{ x=258, y=328 },
{ x=203, y=315 },
{ x=165, y=280 },
{ x=165, y=228 },
{ x=185, y=181 },
{ x=249, y=160 }
}[/lua]
Here is a table I set up with coordinates and was wondering how to have numbers 1-10 connected to it using [lua]display.newText[/lua]
Should I set up a for loop like this
[lua]for i = 1, 10 do
number = display.newText(0, 0, 0, native.systemFontBold, 40)
number.x = t1[i].x; number.y = t1[i].y
end[/lua]

I keep getting errors and I don’t know why!

Thanks for any help!
[import]uid: 51459 topic_id: 16220 reply_id: 316220[/import]

What is the error? What line of your code is it happening on?

Those are questions for you to ask yourself and see if you can figure it out.

Learning to read error messages as cryptic as they can sometimes be, is critical to becoming a solid programmer.

The only thing I see thats a bit odd is that display.newText expects a string as its first parameter and you’re passing a number, though Lua is really good about correcting those. Though there are places where you have to explicitly convert number to a string or a string to a number (ergo the tonumber() and tostring() functions).

So try putting quotes around the “0” for the first parameter, or using tostring(0) instead of just the 0.

But the error message should tell you what the problem is.
[import]uid: 19626 topic_id: 16220 reply_id: 60388[/import]

hey Rob thanks for the quick response!

I figured out my error and I also figured out how to have 0 pop up on the top… I just don’t know how to make it increment from 1-10

I put this up top like you told me

[lua]local number = {}[/lua]

Then I put this for loop later in my code
[lua]for i = 1, 10 do
number[i] = display.newText( 0, 0, 0, native.systemFontBold, 40)
number[i].x = t1[i].x; number[i].y = t1[i].y
number[i]:setTextColor( 255,0,0)
end[/lua] [import]uid: 51459 topic_id: 16220 reply_id: 60390[/import]

Hey Rob I figured it out!
[lua]for i = 1, 10 do
number[i] = display.newText( i, 0, 0, native.systemFontBold, 40)
number[i].x = t1[i].x; number[i].y = t1[i].y
number[i]:setTextColor( 255,0,0)
end[/lua]

I just replaced 0 with i!!

It was that easy!

[import]uid: 51459 topic_id: 16220 reply_id: 60395[/import]