Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Lua 加载模块时出错';(';预计接近';=';_Lua_Coronasdk - Fatal编程技术网

Lua 加载模块时出错';(';预计接近';=';

Lua 加载模块时出错';(';预计接近';=';,lua,coronasdk,Lua,Coronasdk,这段代码是为火炮射击创建函数侦听器的。当我运行代码时,它给了我一个错误问题1。lua:43'('expected near'=' function cannonCharge = function(event) if(event.phase == 'began') then impulse = 0 cannon.isVisible = true Runtime:addEventListener('enterFrame', charge)

这段代码是为火炮射击创建函数侦听器的。当我运行代码时,它给了我一个错误问题1。lua:43'('expected near'='

function cannonCharge = function(event)
  if(event.phase == 'began') then
        impulse = 0
        cannon.isVisible = true
        Runtime:addEventListener('enterFrame', charge)
        print ('cannonCharge')
    end
end

function shot = function(event)
    if(event.phase == 'ended') then

        Runtime:removeEventListener('enterFrame', charge)
        cannon.isVisible = true
        cannon.rotation = 0

        cannonBall = display.newImage('cannon ball.png', 84, 220)
        physics.addBody(cannonBall, {density = 1, friction = 0, bounce = 0})
        cannonBalls:insert(cannonBall)
        print ('shot')

-- Shoot cannon ball
cannonBall:applyLinearImpulse(3, impulse, cannonBall.x, cannonBall.y )

--Collision listener
cannonBall:addEventListener ('collision', ballCollision)

    end
end

function scene:createScene(event)
...
我将侦听器添加到场景中

function scene:enterScene( event )
local group = self.view
background:addEventListener('touch', cannonCharge)
background:addEventListener('touch', shot) 
  end

变量没有类型,只有值有类型

function shot = function(event)
-- ...
end
试一试

如果不将
放在本地
,则变量将是全局变量。应尽量减少全局变量的使用

如果您喜欢更结构化的语法,可以使用:

local function shot(event)
-- ...
end
这相当于:

local shot
shot = function(event)
-- ...
end

您不能在同一对象上分配两个触控监听器。因为这会导致它首先调用哪个函数的冲突。 相反,您需要分配一个触控和一个轻触侦听器,这样就不会有冲突。 背景:addEventListener('tap',cannonCharge)
背景:addEventListener(“触摸”,快照)

我将cannonCharge和shot都更改为local,但它给了我一个错误,“断言失败”。这很好。你已经克服了语法错误。现在你有了一个新问题。当前问题没有足够的细节来回答新问题。如果我不使用touch进行cannonCharge,大炮将不会旋转,只会向前射击。请使用将给我错误断言失败。您可以在enterFrame或Runtime listener中旋转cannon。您能告诉我在哪一点上会出现此错误“(“预期接近”=”。我找不到第43行。
local shot
shot = function(event)
-- ...
end