Function 我正在尝试从另一个堆栈命令中运行一个命令。怎么用?

Function 我正在尝试从另一个堆栈命令中运行一个命令。怎么用?,function,callback,stack,command,livecode,Function,Callback,Stack,Command,Livecode,我在堆栈中有一个回调处理程序,用于查找遥测数据。当它得到一些时,我解析它,然后想保存它 但是,要保存它,需要在同一堆栈中使用其他函数和命令 我可以把它写在卡片上,但是在哪里?我使用openCard结束openCard,这就是卡片中的内容 堆栈具有我需要的所有函数和命令 没有按钮来运行保存代码-我需要它自动运行 如何将代码块放在卡上,然后让堆栈“调用它” 我知道如何从卡中调用命令,但不知道如何从堆栈中调用命令 谢谢你的帮助 Mike通常,您只需在线调用命令处理程序或函数处理程序: on mouse

我在堆栈中有一个回调处理程序,用于查找遥测数据。当它得到一些时,我解析它,然后想保存它

但是,要保存它,需要在同一堆栈中使用其他函数和命令

我可以把它写在卡片上,但是在哪里?我使用openCard结束openCard,这就是卡片中的内容

堆栈具有我需要的所有函数和命令

没有按钮来运行保存代码-我需要它自动运行

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

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

谢谢你的帮助


Mike

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

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
  ...
试着制作一个简单的主处理程序,为上面三个“子例程”调用中的每一个都做一些无聊的琐碎事情。你将在几个小时内成为专家。
这三个人的位置必须得到管理。通常,它们驻留在主处理程序所在的脚本中。但它们可以在LC中的任何位置。

一般来说,您只需在线调用命令处理程序或函数处理程序:

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
  ...
试着制作一个简单的主处理程序,为上面三个“子例程”调用中的每一个都做一些无聊的琐碎事情。你将在几个小时内成为专家。
这三个人的位置必须得到管理。通常,它们驻留在主处理程序所在的脚本中。但是它们可以在LC中的任何位置。

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

  • 调度“命令”以使用param1、param2
  • 发送控制“命令”[及时]
  • (命令、控件)放入tResult
即使命令未由控件处理,调度也会继续。你当然可以检查一下。 Send的优点是您可以及时安排发送,但如果您还想发送一些参数,则发送会有点困难。
如果您调用函数并希望返回结果,则值是很好的候选值。

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

  • 调度“命令”以使用param1、param2
  • 发送控制“命令”[及时]
  • (命令、控件)放入tResult
即使命令未由控件处理,调度也会继续。你当然可以检查一下。 Send的优点是您可以及时安排发送,但如果您还想发送一些参数,则发送会有点困难。
如果调用函数并希望返回结果,则值是很好的候选者。

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

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

尝试在堆栈上创建一个命令,当用户在该卡上时,该命令每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


尝试在堆栈上创建一个命令,当用户在该卡上时,该命令每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

供将来参考:A注意到“openCard”和“preOpenCard”消息可以在堆栈脚本中捕获和处理,只要卡片脚本中没有这样的处理程序。即使有,也可以在卡片脚本处理程序完成后“传递”每条消息;这篇编辑的本意是针对这篇文章的作者,作为编辑毫无意义。它应该是作为注释或答案编写的。供将来参考:a注意到“openCard”和“preOpenCard”消息可以被捕获并在堆栈脚本中工作,只要卡片脚本中没有此类处理程序。即使有,也可以在卡片脚本处理程序完成后“传递”每条消息;这篇编辑的本意是针对这篇文章的作者,作为编辑毫无意义。它应该写下来作为评论或回答。