I’ve just found I am getting a “Runtime error for a bad argument #-2 to ‘insert’ (proxy expected, got nil)”, which after many tests, seems to be due to the amount of local variables within a function.
Does anyone know anything about this?
I’ve just found I am getting a “Runtime error for a bad argument #-2 to ‘insert’ (proxy expected, got nil)”, which after many tests, seems to be due to the amount of local variables within a function.
Does anyone know anything about this?
Lua does have a limit of 200 on local vars. Its suggested that you create a local table and create your vars from there.
Ex: local tableTmp = {} local a = 1 for i=1, 200 do a= a+1 tableTmp[i] = (a) end
Ahhh, well that might explain it. Thanks for the info!
Ok, I’ve been trying to sort a solution for this issue and am still having trouble.
Essentially, I have a lot of collision detection coordinates which is what is causing my local variable number to be 200+
For example:
local levelwallShape = { 240, -160 , 240, 160 , 204, -45 , 205, -122 , 209, -160 }
local levelwallShape1 = { 200, 114 , 199, 60 , 204, -45 , 240, 160 , 208, 160 }
Using the method suggested above won’t work, as I won’t be able to put these tables of coordinates into another table?
Are there any other methods I can use?
You can put tables into tables…
Can you?
I tried and i did not seem to work. I’ll have another play around and see if I can get it working then.
per nick, for example (pseudocode just to give idea):
local allYourShapes = {} allYourShapes["wall1"] = { x,y,x,y,x,y..} allYourShapes["wall2"] = { x,y,x,y,x,y.. } local allYourDisplayObjects = {} allYourDisplayObjects["wall1"] = display.newImage(..whatever.. local allYourBodies = {} allYourBodies["wall1"] = physics.addBody(allYourDisplayObjects["wall1"], "dynamic", { shape=allYourShapes["wall1"] }) -- three total locals, but any number of objects wrapped inside each -- also equivalently the form: allYourStuff.wall1 -- whenever you see the form: allYourStuff["wall1"]
(btw, hitting this limit might be a clue you could use some reorganization anyway)
hth
Lua does have a limit of 200 on local vars. Its suggested that you create a local table and create your vars from there.
Ex: local tableTmp = {} local a = 1 for i=1, 200 do a= a+1 tableTmp[i] = (a) end
Ahhh, well that might explain it. Thanks for the info!
Ok, I’ve been trying to sort a solution for this issue and am still having trouble.
Essentially, I have a lot of collision detection coordinates which is what is causing my local variable number to be 200+
For example:
local levelwallShape = { 240, -160 , 240, 160 , 204, -45 , 205, -122 , 209, -160 }
local levelwallShape1 = { 200, 114 , 199, 60 , 204, -45 , 240, 160 , 208, 160 }
Using the method suggested above won’t work, as I won’t be able to put these tables of coordinates into another table?
Are there any other methods I can use?
You can put tables into tables…
Can you?
I tried and i did not seem to work. I’ll have another play around and see if I can get it working then.
per nick, for example (pseudocode just to give idea):
local allYourShapes = {} allYourShapes["wall1"] = { x,y,x,y,x,y..} allYourShapes["wall2"] = { x,y,x,y,x,y.. } local allYourDisplayObjects = {} allYourDisplayObjects["wall1"] = display.newImage(..whatever.. local allYourBodies = {} allYourBodies["wall1"] = physics.addBody(allYourDisplayObjects["wall1"], "dynamic", { shape=allYourShapes["wall1"] }) -- three total locals, but any number of objects wrapped inside each -- also equivalently the form: allYourStuff.wall1 -- whenever you see the form: allYourStuff["wall1"]
(btw, hitting this limit might be a clue you could use some reorganization anyway)
hth