无法在lua中声明新函数,编译器告诉我包含一个'=';在函数名附近签名
所以我有一个Util.lua文件,我在其中创建了所有函数,这些函数将在我的游戏的所有状态中使用 这就是我的Util文件的样子无法在lua中声明新函数,编译器告诉我包含一个'=';在函数名附近签名,lua,love2d,Lua,Love2d,所以我有一个Util.lua文件,我在其中创建了所有函数,这些函数将在我的游戏的所有状态中使用 这就是我的Util文件的样子 function GenerateQuads(atlas, tilewidth, tileheight) local sheetWidth = atlas:getWidth() / tilewidth local sheetHeight = atlas:getHeight() / tileheight local sheetCounter = 1 local sprit
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
请注意,最后一个函数根本不起作用,所以我只是返回计数器进行测试,给出的错误消息是:
“=”应在“GenerateQuadPowerups”附近
“Powerup”是我使用library class.lua声明的类。当我从Util.lua中删除有问题的函数时,我在Powerup.lua文件中创建的第一个函数也出现了相同的错误。
这是一个类,以备参考
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
Powerup=Class{}
函数加电:init()
self.x=虚拟宽度
self.y=虚拟高度
self.dx=0
self.dy=-10
终止
--我们只需要检查与桨叶的碰撞,因为碰撞只与该类相关
函数加电:碰撞()
如果self.x>paile.x或paile.x>self.x,则
返回错误
终止
如果self.y>划桨.y或self.y>划桨.y,则
返回错误
终止
返回真值
终止
功能加电:更新(dt)
self.y=self.y+self.dy*dt
如果self.y输入错误1
功能generateqADSpowerups()
打字错误2
功能加电:初始化()
打字错误3
功能通电:更新(dt)
self=nil
实现不了任何东西。我想你可能会以某种方式破坏你的通电,但它只会将nil分配给self
,这只是PowerUp:update
的一个局部变量。无论如何,它都会超出范围。您的代码中至少有三处输入错误。它是功能
,而不是功能
。使用带有关键字突出显示的文本编辑器,并在键入时更加小心!