簡體   English   中英

Love2D /.lua - 嘗試調用全局(零值)

[英]Love2D / .lua - attempt to call global (a nil value)

我希望你過得很好。

任何人都可以幫助找到此錯誤的問題嗎? 我很確定“PowerUpBall”的定義是正確的。

此行導致錯誤:src/states/PlayState.lua:39: attempt to call global 'PowerUpBall' (a nil value)

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的文件!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM