[英]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.
我很确定“PowerUpBall”的定义是正确的。
this line is causing the error: src/states/PlayState.lua:39: attempt to call global 'PowerUpBall' (a nil value)此行导致错误:src/states/PlayState.lua:39: attempt to call global 'PowerUpBall' (a nil value)
self.powerUpBall = PowerUpBall(self.ball.x,self.ball.y)
and 'PowerUpBall' is defined as this 'PowerUpBall' 定义为
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编辑:这与 cs50G 课程中的作业有关
Do not forget to require
the file containing PowerUpBall
before using it!在使用之前不要忘记
require
包含PowerUpBall
的文件!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.