I love the ability of corona to quickly get the length of a table. I understand the difference between #table and table.maxn(t). However, I can’t seem to get the right value from a specific set of data. I used Physics editor to create several shapes. I need to be able to get the length of the # of shapes from the data array (b/c it could potentially change). I thought this would be a quick #shapes.data call, but that is returning 0, even though there are multiple items in the list. I’m not sure why, but I just can’t seem to get the length of that data table (this should be simple, but I’m stumped right now). Here’s the code generated in physics editor
function M.physicsData(scale) local physics = { data = { ["pot\_1"] = { { pe\_fixture\_id = "pot\_1", density = 0.5, friction = 2, bounce = 0, isSensor=true, filter = { categoryBits = 1, maskBits = 65535, groupIndex = 0 }, shape = { 41, -28 , 70, 32 , 69, 66 , 7, 96.5 , -53, 80 , -74, 45 , -43, -24 } } } , ["pot\_2"] = { { pe\_fixture\_id = "pot\_2", density = 0.5, friction = 2, bounce = 0, isSensor=true, filter = { categoryBits = 1, maskBits = 65535, groupIndex = 0 }, shape = { 58, -43 , 78.5, 37 , 64, 71 , 3, 96.5 , -55, 78 , -77, 43 , -51, -44 } } } , ["pot\_3"] = { { pe\_fixture\_id = "pot\_3", density = 0.5, friction = 1, bounce = 0, isSensor=true, filter = { categoryBits = 1, maskBits = 65535, groupIndex = 0 }, shape = { -54.5, 51 , -26, -69 , 31, -69 , 50, 70 , 30, 91 , -33, 90 } } } , ["pot\_4"] = { { pe\_fixture\_id = "pot\_4", density = 0.5, friction = 1, bounce = 0, isSensor=true, filter = { categoryBits = 1, maskBits = 65535, groupIndex = 0 }, shape = { 51, -64 , 82, -5 , 48, 80.5 , 2, 98 , -47.5, 80 , -81, 0 , -51, -65 } } } } } -- apply scale factor local s = scale or 1.0 for bi,body in pairs(physics.data) do for fi,fixture in ipairs(body) do if(fixture.shape) then for ci,coordinate in ipairs(fixture.shape) do fixture.shape[ci] = s \* coordinate end else fixture.radius = s \* fixture.radius end end end function physics:get(name) return unpack(self.data[name]) end function physics:getFixtureId(name, index) return self.data[name][index].pe\_fixture\_id end return physics; end
I created a simple function to get the length of the data array:
function physics:getList() print ("data points: "..#self.data) end
But all I get is a big fat 0 (no error, just a 0). I can see 4 items in the array and I can call them individually, but this is giving me 0. What obvious thing am I missing?