When do things get popped off the stack? The question was posed in a comment, and I think it deserves some space as a post, so here we go:
If I have the following script:
0 (>L:MyVariable, number)
will '0' still be on the stack?
No. It won't. Any time we assign a value to a variable, be it a C:, G:, K: or L: variable (remember that you can't assign directly to A:, E:, P:, M:, or R: variables), the value gets popped off the stack. But if we want a copy of it on the stack, we can use the super-intuitive 'd' operator (why the stack operators all use one character instead of splurging and using two or three, such as 'dup', baffles me). 'd' duplicates whatever is on top of the stack, so that when one copy is popped off to be assigned to MyVariable, another copy remains to be used in future operations.
In an attempt to be perfectly clear, I'll give an example:
5 1 d (>L:MyVariable1) + (>L:MyVariable2)
Here's the state of the stack and local variables after each of the 6 steps:
While we're at it, for those of us who haven't looked at the panels SDK documentation in a while, let's review the list of stack operators.
Clears the stack.
Duplicates the value that is on the top of the stack.
Pops and discards the top value on the stack.
Reverses the top and second values on the stack.
Stores the top values in internal registers.
Loads values from the registers on the top of stack.
Stores the top value and pops it from the stack.
Note the somewhat subtle difference between 's0' and 'sp0'.
Well, I think that's all for stack operators for now! Thanks for the question, Tom!
Fun with words: Paparazzi is the plural form of what word? Cheat here.