Search code examples
functioncallbackstackcommandlivecode

How can I run a command from inside another stack command?


I have a callback handler in a stack that looks for telemetry data. When it gets some, I parse it and then want to save it. However, to save it requires other functions and commands in the same stack.

I could put it on the card, but where? I use the openCard end openCard and that's about it in the card.

The stack has all the functions and commands I need. There's no button to press to run the save code - I need it to run automatically.

How can I put the chunk of code on the card and then have the stack 'call it'?

I know how to call commands from the card, but not from the stack.


Solution

  • Generically, you simply call either a command handler or a function handler in-line:

    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
      ...
    

    Try making a simple main handler that does silly trivial things for each of the three "subRoutine" calls above. You will be an expert in a matter of hours. The placement of the three has to be managed. Generally, they reside in the script where the main handler lives. But they can be anywhere in LC.