I'm using the classes lib from CS50 (I'll show in the code below). I have a Shield.lua class for a shield, https://github.com/vinperdom/Colorless/ ... Shield.lua (here, and the class lib is in lib/class.lua).
If I put all the logic inside the update function it works properly, but if I abstract a little with the "move" function, the quad never changes from what it was defined in init. Why?
scope of self in classes
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: scope of self in classes
Hi, welcome to the forums!
You need to use self:move, not Shield:move. Not sure if that's the cause of your problem, though, because it's not very clear to me what you mean.
Code: Select all
function Shield:update(dt)
if love.keyboard.isDown('w') then
Shield:move('up')
elseif love.keyboard.isDown('a') then
Shield:move('left')
elseif love.keyboard.isDown('s') then
Shield:move('down')
elseif love.keyboard.isDown('d') then
Shield:move('right')
end
end
Who is online
Users browsing this forum: Nikki and 2 guests