What's wrong with this line? The compiler says "attempt to index field '?' (a nil value)".
blocks[a] = love.physics.newBody(world, 50 + (20 * a), 50 + (20 * b), 0, 0)
love.physics.newBody() error
Re: love.physics.newBody() error
intensity wrote:blocks[a] = love.physics.newBody(world, 50 + (20 * a), 50 + (20 * b), 0, 0)
It could be that you've created the blocks table but not the blocks[a] tables. Example:
Code: Select all
blocks = {} -- create the first array dimension
for a = 1, 10 do
blocks[ a ] = {} -- create the second array dimension for each a
for b = 1, 10 do
blocks[ a ][ b ] = love.physics.newBody(world, 50 + (20 * a), 50 + (20 * b), 0, 0)
end
end
Re: love.physics.newBody() error
That's probably it. blocks[1][1] would screw up if blocks[1] had no value?
Re: love.physics.newBody() error
Yes. Lua doesn't have multidimensional arrays, just arrays of arrays, i.e.intensity wrote:blocks[1][1] would screw up if blocks[1] had no value?
Code: Select all
blocks = {} -- blocks can be used as an array but blocks[1] has no value
blocks[1][1] = 1 -- errors, blocks[1] is nil
blocks[1] = {} -- now blocks[1] can also be used as an array
blocks[1][1] = 1 -- works
Re: love.physics.newBody() error
Not a compiler. Interpreter.intensity wrote:What's wrong with this line? The compiler says "attempt to index field '?' (a nil value)".
blocks[a] = love.physics.newBody(world, 50 + (20 * a), 50 + (20 * b), 0, 0)
HUGE DIFFERENCE.
Hello, I am not dead.
Re: love.physics.newBody() error
Actually Lua is both, the compiler translates source code into bytecode and the VM interprets the bytecode to carry on the operations defined in the source code.zac352 wrote:Not a compiler. Interpreter.
Re: love.physics.newBody() error
That's an interpreter. Note: I know that lua has a compilable file for making a lua compiler. so yeah.leiradel wrote:Actually Lua is both, the compiler translates source code into bytecode and the VM interprets the bytecode to carry on the operations defined in the source code.zac352 wrote:Not a compiler. Interpreter.
Hello, I am not dead.
Re: love.physics.newBody() error
Yeah, that's debatable. I was just pointing that Lua actually compiles things.zac352 wrote:That's an interpreter.
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 2 guests