I don't know what I'm doing wrong... Im getting the error in the player.draw() function. the bad argument that its talking about is in the love.graphics.rectangle() method. It's saying that v.x is a bad argument. But it should be working. both v.x and v.y should be working. Because its accessing fields of elements within the table or array right? Can someone tell me what I'm doing wrong and how to fix this? much appreciation! Here is my code:
require "scripts.player"
width = love.graphics.getWidth()
block = {}
block.width = 60
block.height = 10
block.speed = 150
block.timer = 0
block.timerLim = math.random(1,2)
block.spawnX = math.random(0, width - player.width)
function block.spawn(x,y)
table.insert(block, {x = x, y = y})
end
function block.move(dt)
for i,v in ipairs(block) do
v.y = v.y + block.speed * dt
end
end
function block.draw()
for i,v in ipairs(block) do
love.graphics.setColor(255,0,255)
love.graphics.rectangle("fill", v.x, v.y, block.width block.height)
end
end
function block.spawnHandler(dt)
block.timer = block.timer + dt
if block.timer > block.timerLim then
block.spawn(spawnX, -10)
block.timer = 0
block.timerLim = math.random(1,2)
block.spawnX = math.random(0, width - block.width)
end
end
-- Parent Functions --
function DRAW_BLOCK()
block.draw()
end
function UPDATE_BLOCK(dt)
block.move(dt)
block.spawnHandler(dt)
end