Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Love2D / .lua – attempt to call global (a nil value)

I hope you’re doing well.

Could anyone help to find the issue with this error?
I’m pretty sure ‘PowerUpBall’ is defined correctly.

this line is causing the error :
src/states/PlayState.lua:39: attempt to call global ‘PowerUpBall’ (a nil value)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

self.powerUpBall = PowerUpBall(self.ball.x,self.ball.y)

and ‘PowerUpBall’ is defined as this

PowerUpBall = Class{}

function PowerUpBall:init(x,y)
    self.x = x
    self.y = y
    self.dy = 15
    self.spawned = true
    self.achieved = false
end

function PowerUpBall:collides(target)
    if self.x + 16 > target.x and self.x < target.x + target.width and self.y > target.y and self.y < target.y + 16  then
        self.spawned = false
        self.achieved = true
    end
end

function PowerUpBall:update(dt)
    self.y = self.y + self.dy * dt
end


function PowerUpBall:render()
    if self.spawned == true then
        love.graphics.draw(gTextures['main'],gFrames['powerup'], self.x,self.y)
    end
end

I appreciate all comments

EDIT: This is related to an assignment in cs50G course

>Solution :

Do not forget to require the file containing PowerUpBall before using it!

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading