scope of self in classes

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
vinperdom
Prole
Posts: 1
Joined: Wed Oct 21, 2020 1:53 am

scope of self in classes

Post by vinperdom »

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?
User avatar
pgimeno
Party member
Posts: 3550
Joined: Sun Oct 18, 2015 2:58 pm

Re: scope of self in classes

Post by pgimeno »

Hi, welcome to the forums!

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
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.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 194 guests