无法在 lua 中声明新函数,编译器告诉我在函数名称附近包含一个“=”符号

Unable to declare a new function in lua, compiler tells me to include an '=' sign near the name of the function

所以我有这个 Util.lua 文件,我在其中制作将在游戏的所有状态下使用的所有功能。

这就是我的 Util 文件的样子

function GenerateQuads(atlas, tilewidth, tileheight)
local sheetWidth = atlas:getWidth() / tilewidth
local sheetHeight = atlas:getHeight() / tileheight

local sheetCounter = 1
local spritesheet = {}

for y = 0, sheetHeight - 1 do
    for x = 0, sheetWidth - 1 do
        spritesheet[sheetCounter] =
            love.graphics.newQuad(x * tilewidth, y * tileheight, tilewidth,
            tileheight, atlas:getDimensions())
        sheetCounter = sheetCounter + 1
    end
end

return spritesheet
end


function table.slice(tbl, first, last, step)
local sliced = {}

for i = first or 1, last or #tbl, step or 1 do
  sliced[#sliced+1] = tbl[i]
end

return sliced
end


funtion GenerateQuadsPowerups()
  local counter = 1
  local quads = {}
  return counter
end

请注意,最后一个功能根本不起作用,所以我只是返回计数器进行测试,给出的错误消息是:

'=' expected near 'GenerateQuadsPowerups'

“Powerup”是 class 我声明使用库 class.lua。当我从 Util.lua 中删除有问题的函数时,我在 Powerup.lua 文件中创建的第一个函数出现了同样的错误。

这里是class以备参考

Powerup = Class{}

funtion Powerup:init()
  self.x = VIRTUAL_WIDTH
  self.y = VIRTUAL_HEIGHT
  self.dx = 0
  self.dy = -10
end

-- we only need to check collision with the paddle as only that collisionis relevant to this     class
function Powerup:collides()
  if self.x > paddle.x or paddle.x > self.x then
    return false
  end

  if self.y > paddle.y or self.y > paddle.y then
    return false
  end

  return true
end

funtion Powerup:update(dt)
  self.y = self.y + self.dy * dt

  if self.y <= 0 then
    gSounds['wall-hit']:play()
    self = nil
  end
end

我不明白这里发生了什么

错字 1

函数 GenerateQuadsPowerups()

错字 2

函数 Powerup:init()

错字 3

函数 Powerup:update(dt)

self = nil 顺便说一句,一无所获。我猜你认为你可以以某种方式破坏你的 PowerUp 但它只会将 nil 分配给 self 这只是 Powerup:update 的局部变量。无论如何它都会超出范围。