Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
How to pass a list of number dynamically? — Gideros Forum

How to pass a list of number dynamically?

edited May 2013 in General questions
Hi guys,

In this function:
b2.PolygonShape:set(vertices)
vertices: A list of numbers that contains the x, y coordinates of the vertices sequentially

Now I want to build a polygon dynamically, that mean I must pass it coordinates to this function but I don't know how to build and pass a list of numbers.

I tried with a string:
b2.PolygonShape:set('1,2,3,4,5,6')
or an array:
b2.PolygonShape:set({1,2,3,4,5,6})
but got these errors:
bad argument #1 to 'set' (number expected, got string)
bad argument #1 to 'set' (number expected, got table)

Comments

  • ar2rsawseenar2rsawseen Maintainer
    Accepted Answer
    Hello @thanhquan1512
    it should be like this:
    local t = {1,2,3,4,5,6}
    b2.PolygonShape:set(unpack(t))
    +1 -1 (+2 / -0 )Share on Facebook
Sign In or Register to comment.