function:
Code: Select all
local function addBlock(x,y,w,h)
local block = {x=x,y=y,w=w,h=h}
blocks[#blocks + 1] = block
world:add(block, x,y,w,h)
end
Code: Select all
addBlock(50, 100, 200, 32)
addBlock(150, 100, 100, 32)
Code: Select all
local function addBlock(x,y,w,h)
local block = {x=x,y=y,w=w,h=h}
blocks[#blocks + 1] = block
world:add(block, x,y,w,h)
end
Code: Select all
addBlock(50, 100, 200, 32)
addBlock(150, 100, 100, 32)
MrFariator wrote: ↑Fri May 12, 2023 10:17 pm What's the error? Always make sure to attach an error log if you want help. The code you posted doesn't really tell us anything, assuming the variables "blocks" and "world" actually exist.
Code: Select all
local blocks = {} -- define the blocks table
local function addBlock(x,y,w,h)
local block = {x=x,y=y,w=w,h=h}
blocks[#blocks + 1] = block
world:add(block, x,y,w,h)
end
addBlock(50, 100, 200, 32)
addBlock(150, 100, 100, 32)
Code: Select all
local function addBlock(x,y,w,h)
local block = {x=x,y=y,w=w,h=h}
blocks[#blocks + 1] = block -- the code can't find the definition of "blocks", so you'll get a "indexing a nil value" error here
world:add(block, x,y,w,h)
end
local blocks = {}
addBlock(50, 100, 200, 32)
addBlock(150, 100, 100, 32)
Users browsing this forum: CutePenguin and 7 guests