hello there, gideros people.
Can anybody tell me how to store coordinates in a table, please?
What I am trying to achieve:
I have a set of coordinates that I would like to use to draw a shape:
[[[79,39],[82,41],[84,48]],
[[84,48],[89,52],[90,59]],
[[70,29],[77,35],[79,39]],
[[66,67],[63,54],[66,50]],
I would like to store these coordinates in a table and draw the shape something like:
shape:lineTo(0, -40)
shape:lineTo(20, 0)
shape:lineTo(-20, 0)
shape:lineTo(0, -40) |
But using a for loop:
for c = 1, #coords do
shape:lineTo(coords[c].x, coords[c].y)
end |
Any help would be appreciated. Thank you.
Comments
Lua tables are very convenient.
Useful info about original Lua tables construction syntax:
https://www.lua.org/pil/3.6.html
And info about enhanced table syntax in Gideros:
http://docs.giderosmobile.com/reference/enhancement/easyarray#Better and easier syntax for arrays
Likes: MoKaLux
"What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
“The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
That worked! What I did:
Thank you very much for your help. Do you think that is the right/best way of doing it?
Perfomance-wise, 'table.insert(shape_points, {0,40}' is slower than 'shape_points[1]={0,40}'
(with 'table.insert' engine will have to pre-check what stuff is already there in table)
But you won't notice it unless you are filling lots of tables in one frame
"What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
“The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
Likes: SinisterSoft
Likes: MoKaLux
https://deluxepixel.com
Likes: SinisterSoft
or
Likes: MoKaLux, SinisterSoft
https://play.google.com/store/apps/developer?id=razorback456
мій блог по гідерос https://simartinfo.blogspot.com
Слава Україні!
Not doing so would draw a funny line from 0,0 to the first actual coordinate where you want to actually begin drawing from.
And with tables.. use table[#table + 1] = whatever to append to the end of a table quicker than table.insert. I suppose you could always use table[n] = whatever but I think table[#table + 1] = whatever is better
Ok, from now on when inserting things in tables I will use table[#table + 1] = whatever.
Thanks a lot all of you for your help and your precious advice.
I need more practice but I don't want to burn out!
and if you burn out.. don't worry.. it will only be for a little while.. and then you'll be right back at it!
Likes: MoKaLux, talis