119
In programming terms we often need to execute the same sequence of commands several times during the operation of a
program so we have the Goto Subroutine
*GS
label
and Subroutine Return
*SR
. The number of subroutines is limited
by the number of labels but it should be noted that the script engine does not support nesting of subroutines. Such
constructs should be avoided in simplistic systems. It should be noted that a subroutine has an overhead of 9 bytes
before any commands are added (assuming a single character label) and so needs to be used carefully.
To demonstrate the use of a subroutine, our simple example could be extended to:
NS
*LAloop
*GSsub
*GTloop
*LAsub
LN
WTHello
*SR
The script first clears the screen and then runs round the loop but each time round the loop it heads off to the subroutine
“sub” and executes the
LN
Line New and
WT
Write Text commands.
Key Handling
Most users will want to have some control over the data being presented to them and so we need to be able to go to a
label based on a key press. This is achieved by using the
*GK
n
,
label
Goto Key command, where
n
is the number of
the key to be acted upon i.e
*GK1,one
would check to see if Key 1 is pressed and if it was it would go to the label
“one”. By using a value of zero for
n
then the engine will go to the label if
ANY
of the keys are pressed.
NS
WTPress Key 1 or 2
*LAloop
*GK1,one
*GK2,two
*GTloop
*LAtwo
CM7,0
WTScreen 2
EL
*GTloop
*LAone
CM7,0
WTScreen 1
EL
*GTloop
In this example the script clears the screen and writes up the message instructing the user to press key 1 or 2 it then
drops into a loop which checks the keys. If key 1 is pressed the flow is altered to go to label one. This causes the script
engine to write “Screen 1” on the bottom line of the screen and clears the rest of the line. It then reverts to the scanning
of the keys. The same applies to key 2.
The display has a two local menus that are accessed by pressing a combination of keys. The main menu is used to
configure the display, and is accessed by pressing the “
P
” and “
E
” keys simultaneously. The Quick Access menu is
used to provide a local operator a few facilities that may be needed, without giving the ability to mis-configure the
display. The Quick Access menu is reached by pressing the “
P
” and “
B
” keys simultaneously. There is a slight
possibility that these key combinations may interfere with a script that has been written, so the facility has been added
to redefine the key that accesses the menus. The
*MK
n
,
m
,
p
Menu Key command is used for this purpose, where
n
is
the number of the key (1 – 6) that should be pressed to enter the menu,
m
is the type of menu to be redefined (0 = main
menu and 1 = Quick Access menu), and
p
is set to 0 to allow the new key to be used in addition to the default key
combination, or
p
is set to 1 to inhibit default key combination. The command may be issued twice to redefine both
menu keys, and the default key combinations can be restored by setting
n
to a value of 0
As an example, the command
*MK3,1,1
will disable the “
P
” and “
B
” key combination to the Quick Access menu,
but will enter this menu whenever button 3 is pressed.