Love2D / .lua - 尝试调用全局(零值)
Love2D / .lua - attempt to call global (a nil value)
希望你一切顺利。
谁能帮忙找出这个错误的问题所在?
我很确定 'PowerUpBall' 定义正确。
此行导致错误:
src/states/PlayState.lua:39:尝试调用全局 'PowerUpBall'(零值)
self.powerUpBall = PowerUpBall(self.ball.x,self.ball.y)
和'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
感谢所有评论
编辑:这与 cs50G 课程中的作业有关
在使用前不要忘记 require
包含 PowerUpBall
的文件!
希望你一切顺利。
谁能帮忙找出这个错误的问题所在? 我很确定 'PowerUpBall' 定义正确。
此行导致错误: src/states/PlayState.lua:39:尝试调用全局 'PowerUpBall'(零值)
self.powerUpBall = PowerUpBall(self.ball.x,self.ball.y)
和'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
感谢所有评论
编辑:这与 cs50G 课程中的作业有关
在使用前不要忘记 require
包含 PowerUpBall
的文件!