【问题标题】:In Corona SDK, how can I stop a function?在 Corona SDK 中,如何停止某个功能?
【发布时间】:2014-12-07 12:59:29
【问题描述】:

有没有办法停止一个函数而不使它成为nil?像“function.stop”之类的东西?

【问题讨论】:

  • 你的“停止”是什么意思?随时返回函数?
  • 请改进您的问题

标签: function lua coronasdk


【解决方案1】:

您可以在函数结束前退出函数,只需调用“return”s 语句:

local function doSomething()
    if leaveEarly then
        return
    else 
        -- do other stuff
    end
    -- do more stuff
 end

【讨论】:

    【解决方案2】:

    根据documentation使用do return end

    function foo ()
      do return end
      ...             -- statements not reached
    end
    

    【讨论】:

    • 我的意思是,当一个事件发生时,我希望几个函数停止。像" function onCollision Function.stop end
    【解决方案3】:

    除非你调用它,否则函数不会做任何事情。如果您正在谈论事件侦听器,例如

    Runtime:addEventListener( "enterFrame", win)
    --win is the name of the function, which is called once every frame
    

    然后您可以像这样删除该事件侦听器:

    Runtime:removeEventListener( "enterFrame", win)
    --now win is no longer called every frame
    

    如果这不是你的意思,你能发布一些你的代码吗?

    【讨论】:

      猜你喜欢
      • 2016-04-09
      • 1970-01-01
      • 2013-08-17
      • 2014-01-01
      • 1970-01-01
      • 2015-01-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多