【问题标题】:How can I run a command from inside another stack command?如何从另一个堆栈命令中运行命令?
【发布时间】:2020-05-20 22:31:19
【问题描述】:

我在堆栈中有一个回调处理程序,用于查找遥测数据。当它得到一些时,我解析它然后想保存它。但是,要保存它,需要在同一堆栈中使用其他函数和命令。

我可以把它放在卡片上,但是放在哪里?我用的是openCard端的openCard,卡里就差不多了。

堆栈具有我需要的所有功能和命令。没有按钮可以运行保存代码 - 我需要它自动运行。

如何将代码块放在卡上,然后让堆栈“调用它”?

我知道如何从卡中调用命令,但不知道从堆栈中调用命令。

【问题讨论】:

    标签: function callback stack command livecode


    【解决方案1】:

    通常,您只需内联调用命令处理程序或函数处理程序:

    on mouseUp -- a "main" handler
      doSomething -- a command handler 
      dosomethingElse -- another command handler 
      put doYetAnotherThing(paramList) into field 1 -- a function handler
    end mouseUp
    
    on doSomething
      well, do something
    end doSomething
    
    on doSomethingElse
      you get the picture
      ...
    

    尝试制作一个简单的主处理程序,为上面的三个“subRoutine”调用中的每一个都做一些琐碎的事情。您将在几个小时内成为专家。 这三个人的位置必须管理。通常,它们驻留在主处理程序所在的脚本中。但它们可以在 LC 的任何地方。

    【讨论】:

      【解决方案2】:

      如果您想从另一个脚本调用卡片(或任何其他控件)中的处理程序,可以使用以下命令之一:

      • 调度命令”到控制param1param2,...
      • 发送命令”到控制 [在时间]
      • value(command, control) 放入tResult

      即使 command 没有被 control 处理,

      Dispatch 也会愉快地继续。你当然可以检查。 Send 的优点是您可以及时安排发送转发,但如果您还想发送一些参数,那就有点困难了。 如果您调用函数并希望返回结果,则值是很好的候选者。

      【讨论】:

        【解决方案3】:

        请注意,只要卡片脚本中没有此类处理程序,“openCard”和“preOpenCard”消息就可以被捕获并在堆栈脚本中工作。即使有,您也可以“传递”每条消息在卡片脚本处理程序完成后";

        【讨论】:

          【解决方案4】:

          尝试在堆栈上创建一个命令,当用户在该卡上时,该命令每 X 次调用一次。这个命令必须被调用到它自己和你用来获取数据的其他操纵器。这个机械手将负责保存数据。

          # Code on the card
          local sTelemetryData
          
          on openCard
           // If the card belongs to the pile where all the telemetry is or if this pile is a library.
           getTelemetryData
          // otherwise you will have to call the getTelemetryData command. You can use send, disparsh, or call.
          // call "getTelemetryData" to stack "stack name"
          end openCard
          
          # Code on the stack
          constant kTime = 100
          local sPendingMessageID
          
          on getTelemetryData
             
             if the short name of this card is not "TelemetryData"
             then exit getTelemetryData
             
             if sPendingMessageID is a number
             then cancel sPendingMessageID
             
             // call the commands and functions that look up the telemetry data.
             // The data must be stored in the sTelemetryData variable to save it and at once use this variable as a flag
            
             if sTelemetryData is not empty then
                // The data is sent to be saved
             end if
             
          put empty into sTelemetryData
             send "getTelemetryData" to me in kTime milliseconds
             put the result into sPendingMessageID
          end getTelemetryData
          
          

          【讨论】:

            猜你喜欢
            • 2022-01-24
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多