在PONG游戏中LUA为CS50尝试索引nil值

我一直在尝试运行这个程序,主要部分运行得非常好,但当我尝试运行重置函数时,它会显示Ball.lua:14:尝试索引全局变量'self'(一个nil值)

我对LUA非常陌生,因此不知道如何解决这个问题。 谢谢你的帮助。

Ball = Class{}

function Ball:init(x, y, width, height)
    self.x = x
    self.y = y
    self.width = width
    self.height = height
    self.dx = math.random(2) == 1 and -100 or 100
    self.dy = math.random(-50, 50)
end

function Ball.reset()
    --将球的位置设为中间开始
    self.x = VIRTUAL_WIDTH / 2 - 2
    self.y = VIRTUAL_HEIGHT / 2 - 2

    self.dx = math.random(2) == 1 and -100 or 100
    self.dy = math.random(-50, 50) * 1.5
end

function Ball:update(dt)
    self.x = self.x + self.dx * dt
    self.y = self.y + self.dy * dt
end

function Ball:render()
    love.graphics.rectangle('fill', self.x, self.y, self.width, self.height)
end
点赞