Scripting - saving a value for later use

I’m just learning the Maestro and scripting language, making short programs to try out techniques. I am trying to use a momentary contact button as a start / stop switch. I use a simple WHILE loop at the top to wait until the button is pressed, the script then goes to an action loop, also a WHILE dependant on looking for a button press. The button’s GET_POSITION and comparison test are at the end of the action loop.

The start works fine, but I realized the button must be in the pressed state when the action loop gets to the end where the test is. I can add a lot more tests to the action loop and a bunch of IFs and GOTOs, but that will get messy. I would like to use something like a flag variable, to sense if a button is pressed at several points in the action loop, but saving the comprison TRUE/FALSE value for a single WHILE test at the bottom. Is it possible to stick a value in the stack and leave it unmolested until called for?

Hello,

Which Maestro do you have? On the Mini Maestro 12, 18, and 24, the PEEK and POKE script commands do exactly what you want. On the Micro Maestro you have to improvise something. For example, you could use ROLL a bunch of times, or alternatively store the value to an unused servo channel and recover it later with the GET_POSITION command.

-Paul

After searching the forumn for other topics, I think dawn is breaking… I need to change my thinking to putting global variables in the bottom of the stack, instead of high. Does PEEK cause the stack to drop above the PEEKed register, or does the value remain until POKEd with a different value (or consumed by a function if it becomes the top value)?

Hello,

Yes, that is what I am suggesting. Putting variables on the bottom allows you to forget about them until you need them. PEEK does not remove anything - it just copies the value to the top of the stack.

-Paul