Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
How to pass a table of vertices to b2.PolygonShape:set()? — Gideros Forum

How to pass a table of vertices to b2.PolygonShape:set()?

DrixDrix Member
edited November 2012 in General questions
Please, how could I pass a table of vertices, as the following, to b2.PolygonShape:set()?
local vertices = {-100,20,  160,20,  160,34,  -160,34}
I tried this:
local objShape = b2.PolygonShape.new()
objShape:set(table.concat(vertices, ","))
...but it doesn't work because the return of table.concat is an string.

I really really need that, because I import the arrays of vertices from text files. Please, is there any chance to make the set function to accept a table instead?

Thanks in advance

Comments

  • DrixDrix Member
    edited November 2012
    I got it:
    function MyConvertTableToItensSequence(tb, i)
       if tb[i] ~= nil then
          return tb[i], MyConvertTableToItensSequence(tb, i + 1)
       end
    end
     
    ...
     
    objShape:set(MyConvertTableToItensSequence(vertices, 1))
    But I should say that passing a table to this kind of function would be more comfortable.
  • zvardinzvardin Member
    Accepted Answer
    You can use the unpack lua function

    Likes: Drix, atilim

    +1 -1 (+2 / -0 )Share on Facebook
  • DrixDrix Member
    edited November 2012
    Thanks @zvardin! I did not know that function. Much simpler.
  • afaik, unpack function is expensive. So, be careful.
Sign In or Register to comment.