use-revolution digest, Vol 1 #380 - 12 msgs

J. Landman Gay jacque at
Fri May 3 20:54:01 EDT 2002

Dar Scott wrote:

> I have been putting library-like scripts in groups.  I'd like to 
> consider library stacks.  Would these be substacks if I want to 
> include them in the same file?  Or am I looking that the 
> organization wrong?
> Would the main stack be in the message path twice?  That is, both 
> before the library stacks and after?

No, the main stack would only receive the message once, just after the 
substack gets it (assuming the substack has been put in use.) Another 
method that's ideal for library scripts is the "insert" command, which 
places a script into the message hierarchy without needing to use a 
separate stack. You can write a whole library of handlers and store it 
in any available object's script. When you want to put the script into 
use, you insert it:

     insert script of <the object> into front
or: insert script of <the object> into back

The object can be anything that's handy and is simply used as a storage 
place. Once inserted, the script acts as a layer in the message 
hierarchy until you remove it or Rev quits. If a script is inserted into 
the front, it gets all messages before anything else. For example, 
clicking a button usually sends "mouseup" to the button first, and then 
on through the hierarchy until the message reaches the Rev engine. If a 
script is inserted into the front, the frontscript will receive the 
"mouseup" message *before* the button does. This is a good technique for 
something like painting tools, where you want to change the normal 
behavior of a mouse event or some other action.

Scripts inserted into the back are similar to the scripts of stacks put 
"in use" -- the script is inserted behind everything else, and doesn't 
receive messages until almost the whole hierarchy has been traversed. 
The difference between "insert into back" and "start using stack" is 
that stacks in use receive messages before the Home stack gets them, and 
scripts inserted into the back receive the message after the Home stack 
gets them. In a standalone where there is no Home stack, both methods 
are pretty much equivalent.

For library scripts, insertion is a good technique because it doesn't 
require that you have a separate stack to store the script into. You can 
store scripts intended for insertion inside hidden objects, properties, 
unused cards, whatever. On the other hand, if you develop a spiffy 
library and you want to distribute it to others, then putting it into a 
stack that you can send to people is a good technique.

Jacqueline Landman Gay         |     jacque at
HyperActive Software           |

More information about the use-livecode mailing list