tables, love.graphics.setColor and math.random problems
Posted: Sat Aug 15, 2015 7:01 pm
Hi guys, i have a small problem with a game i'm working on. I have created a function for a simple circle to spawn as a random color in a random location with the identity of 'food' which when i run i get this error:
"food.lua:26" bad argument #1 to 'setColor' (number expected, got nil)
I don't see what i am doing wrong. I could create a work around and change: to but that's not the point and i don't see why this isn't working and i believe knowing whats going wrong here could benefit myself and the community.
Thanks in advance,
Oli.
"food.lua:26" bad argument #1 to 'setColor' (number expected, got nil)
Code: Select all
food = {
foodid = 0,
radius = 3,
segments = 20
}
function food:load()
fod = {
x=math.random(1000),
y=math.random(1000),
r=math.random(10, 255),
g=math.random(10, 255),
b=math.random(10, 255),
}
self.foodid = self.foodid+1
setmetatable(fod, { __index = food })
return fod
end
function food:update( dt )
end
function food:draw( dt )
love.graphics.setColor(self.r, self.g, self.b) -- THIS IS LINE 26 WITH THE ERROR
love.graphics.circle("fill", self.x, self.y, self.radius, self.segments)
end
function food:respawn()
self.x=math.random(1,1000)
self.y=math.random(1,1000)
end
function UPDATE_FOOD( dt )
food.update(dt)
end
Code: Select all
self.r, self.g, self.b
Code: Select all
fod.r, fod.g, fod.b
Thanks in advance,
Oli.