When something happens that would be interesting for a script to react to, MoStacks sends a message to the object in question, and if the object has a script with the right name, i.e. with the name of the message, that script gets executed.
In principle MoStacks should have, like HyperTalk, a few dozens methods, because there are quite a lot of events where it makes sense to be able to append a script, but so far only a few messages are implemented, the ones described below.
Furthermore, in principle, scripts should be searched and then executed along the 4-level object hierarchy. It should be possible to write a script that reacts to control messages at a card, so that the script gets executed for each control on the card, but again is not yet fully working. (Such a script is possible and does get executed, but there is no way yet to ask which of the many possible controls is addressed by the message, and that makes the mechanism hardly useful.)
The general format of a script for a message is:
on <messageName> <statements> end <messageName>
An actual example looks like this:
on openStack answer "Welcome to this beautiful MoStack" end openStack
The select Message
Probably the most often used and the most useful message is select which is sent to a control of type Command when its menu entry is selected (hence the name) or when the corresponding button is tapped. It is described in detail in its own chapter Select Message.
The openStack Message
The openStack message is sent once to any stack when you open it.
You program a script reacting to this message, naturally enough, at the stack level, by using the button Script... on then Edit Stack Window.
An example for using an openStack script would be a stack with reminders, where the script checks right after stack opening whether the Remind at date of any entry is reached and warns you about this.
Be careful what you program into such a script because there is not yet any way to prevent it from running after a stack opens. If that script causes a problem, in the worst case that can make a stack unusable.
The openCard Message
The openCard message is sent to a card when it "opens" i.e. when the display, the card window or the card view, changes to it.
You can program a script reacting to this message on the card level, for a specific card, with the help of the Script... button the Edit Cards Window, or on the background level, where the script will react to the opening of any card of the given background, or even on the stack level, where it will react to the opening of any card in the whole stack.
It may be that an openCard script will execute once again even with the card already displayed, e.g. on UIQ3 after certain dialogs like Card Info are displayed and then closed, because after a change of card properties a refresh of the display is necessary that gets counted as an "opening" of the card.
The closeField Message
This message, send to a field with a changed value when it looses focus, is described in chapter Field Messages.
The exitField Message
This message, send to a field with an unchanged value when it looses focus, is described in chapter Field Messages.