电晕错误:尝试调用全局"startButtonListeners" < nil值> [英] Corona error: attempt to call global "startButtonListeners" <a nil value>

查看:73
本文介绍了电晕错误:尝试调用全局"startButtonListeners" < nil值>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用电晕制作一个主菜单,但是遇到一个错误,它使我发疯.

I'm making a main menu scene in corona, however I've come across an error and its driving me crazy.

编译器使我难以理解它是什么,但我可以指出其中的两个问题:

The compiler makes it confusing for me to understand what it is but I can point out 2 problems from it:

  • 尝试调用全局"startButtonListeners"
  • [C]在函数"startButtonListeners"中

这是代码部分:

 function scene:enterScene(event)
    local group = self.view 
    startButtonListeners('add')

    function startButtonListeners(action)
      if(action == 'add') then  
         aboutBtn:addEventListener('tap', showCredits)
         startBtn:addEventListener('tap', startBtn)
      end 

      local function onSceneTouch( self, event )
        if event.phase == "began" then
        storyboard.gotoScene( "scene1", fade, 500 )
        return true
      end
    end 
end

推荐答案

将函数startButtonListeners的位置更改为结尾;函数定义完成后:

Change the location of your function startButtonListeners to the end; after your function definition is complete:

scene:enterScene(event)
    local group = self.view 

    function startButtonListeners(action)
      if(action == 'add') then  
         aboutBtn:addEventListener('tap', showCredits)
         startBtn:addEventListener('tap', startBtn)
      end 

      local function onSceneTouch( self, event )
        if event.phase == "began" then
        storyboard.gotoScene( "scene1", fade, 500 )
        return true
      end
    end 
    startButtonListeners('add')
end

这篇关于电晕错误:尝试调用全局"startButtonListeners" < nil值>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆