More on MicroScript Segments


In our first lesson, "A Taste of MicroScript," we drew a figure (graphic) segment on the screen and created a short MicroScript program, or script, with instructions to make it to move around the screen. Now, let's take a closer look at segments, which are the basic elements of a MicroScript script. In the MicroScript programming language, segments are regarded as "actors" in a "scene" that the MicroScript script describes.

As previously stated in our first lesson, a MicroScript script is created inside a MicroScript stencil, which is a variation of the standard Basic Figure Editor file. In the BTRON-specification operating system, a file is referred to as a "real object," and the link to that file is called a "virtual object." Inside a MicroScript real object, only two types of elements exist: (1) segments, of which there are three types; and (2) "script real objects," which lie beneath "script virtual objects."

The three types of MicroScript segments are:

(1) Figure (Graphic) Segment

A figure segment is the minimum unit in a MicroScript script. A figure segment is created with standard system graphic tools inside the Basic Figure Editor, and it is identified by a "segment name character frame," i.e., the symbol @ followed by a name (e.g. "@Segment1"). A figure segment plus a segment name becomes an "actor" when grouped together with the "Make Group" command.

(2) Character Segment

Characters can also become segments in MicroScript. Since they are created with the text box tool of the Basic Figure Editor, they are technically a type of figure segment. Figure segments are used for displaying and/or inputting numerals and characters in MicroScript scripts. The text box of a character segment can hold a maximum of 1,024 characters.

(3) Virtual Object Segment

Virtual objects, which are links to real objects, are dealt with as segments when they are placed inside the MicroScript program stencil. As a result, they become "actors." However, if the virtual object begins with the word SCRIPT, it is not dealt with as an actor, but rather the repository of a MicroScript script, or a "script real object."

The script real object is an opened virtual object whose title begins with the word SCRIPT. It contains the script that operates on the actors. A maximum of eight scripts can be created inside a figure real object. In such case, if they are in order one after the other, they are interpreted in order from the innermost (the one farthest back) script.

Points to Remember:

Segment names can be no longer than 12 characters, not including the symbol "@."

Segment names cannot begin with a numeral.

Certain control characters and symbols cannot be used cannot be used in segment names. These are:

SPACE
TAB
comma ( , )
colon ( : )
semicolon ( ; )
long vertical bar ( | )
circumflex accent ( ^ )
ampersand ( & )
equals sign ( = )
exclamation mark ( ! )
not equal-to sign (equals sign with slash through it)
less-than sign ( < )
greater-than sign ( > )
less-than or equal-to sign (less-than sign with equals sign under it)
greater-than or equal-to sign (greater than sign with equals under it)
left-pointing angle bracket ( ‹ )
right-pointing angle bracket ( › )
plus sign ( + )
minus sign ( - )
asterisk ( * )
slash ( / )
percent sign ( % )
multiplication sign ('x' symbol)
division sign (line with dot above and dot below)
difference-between sign ( ~ )
overscore ( &hibar; )
left parenthesis ( ( )
right parentheses ( ) )
left square bracket ( [ )
left square bracket ( ] )
double high-9 quotation mark ( “ )
double high-reversed-9 quotation mark ( ” )
left-pointing double quotation mark ( `` )
right-pointing double quotation mark ( ´´ )
period ( . )
number sign ( # )
yen sign ( ¥ )
apostrophe ( ' )
 
Note: A list of the above symbols appears on page 266 of Personal Media Corporation's Maikuro sukuriputo nyuumon [An introduction to MicroScript]. Since many of these symbols are "difficult to extract" from an MS-Windows system, explanations have been added above for clarification. Also, please take particular note that certain of these control characters and symbols, such as SPACE, are easy to write inadvertently into the name of a segment. So please be sure to go over the list a few times and commit it to memory.

A Simple Script for Displaying a Character Segment

Now let's write a short script to illustrate how a character segment is created and used. This script will make a character segment appear, move it from top to bottom, and then make it disappear. As in the previous lesson, we begin by creating a MicroScript stencil, which is a version of the standard system graphics file. This is done by opening the Stencil Box, selecting the MicroScript virtual object, and moving a copy of the MicroScript virtual object into an open window. When the dialog box appears, write "Character Segment," and then press "Set." A MicroScript real object will open.

Inside the opened MicroScript real object, select the text input tool (this is done by clicking the box with the hiragana character for "a" in it; it is located in the tool palette). After you have selected this tool, at coordinates x 31, y 31, write the following: "These letters are one segment." Next, using the same tool, write below that "@TEXT1." Finally, simultaneously select these two character strings using the selection tool (this is activated by clicking the "finger-for-pointing icon" in the tool palette), and then choose the "Make Group" command, which is in the submenu of the Edit menu. With that, the creation of the segment has been completed.

In order to write the script, which we will simply call "Character," we select the Basic Text Editor virtual object in the Stencil Box, and move a copy of it into the open MicroScript real object. A dialog box then appears asking us to write in an appropriate name. Since this is a "script real object," the name has to begin with "SCRIPT." Thus we write "SCRIPT Character." Once that is done and we press the "Set" button, the real object opens allowing us to write the following program.

VERSION 2
PROLOGUE
SLEEP 1000
APPEAR TEXT1
SLEEP 1000
MOVE TEXT1: 31, 131 @
SLEEP 1000
DISAPPEAR TEXT1
END

In ordinary English, what this means is:

This is a program written in Version 2 of MicroScript
Initialize MicroScript interpretation resources
Wait for 1000 milliseconds
Make the segment TEXT1 appear on the screen
Wait for 1000 milliseconds
Move the segment TEXT1 to point 31, 131 absolute
Wait for 1000 milliseconds
Make the segment TEXT1 disappear from the screen
End execution

For those who do not have access to a BTRON machine to run the above script, what it does is display the character segment ("These letters are one segment."), move it directly below the place it first appeared, and then make it disappear. The purpose is to demonstrate that a string of characters can be used as a single unit and moved about the screen in the same manner as a figure segment.

A Simple Script for Displaying, Opening, and Closing a Virtual Object Segment

The second type of segment described above is the virtual object segment. This is actually easier to handle than figure or character segments, because a virtual object segment does not have to be "tagged" with a "segment name character frame," i.e., the symbol "@" plus a name. In fact, it is impossible to add such a tag to a virtual object--try it and see for yourself. Thus a virtual object is used in the MicroScript programming environment without any modifications.

We begin creating our second program the same way we created our first--by peeling off a MicroScript stencil leaf from the MicroScript virtual object inside the Stencil Box. When the dialog box appears, write "VO Segment" and press "Set." A MicroScript real object will then open up. Inside this, let's set a Basic Text Editor virtual object, which is created by peeling off a Basic Text Editor leaf from the Basic Text Editor virtual object in the Stencil Box. When the dialog box appears, write in "Example" and press "Set." Inside the real object attached to this virtual object, let's write a simple message: "This is how you display, open, and close a virtual object with MicroScript."

Finally, we write the program, which we will call "VO Open." We do this by peeling yet another leaf from the Basic Text Editor virtual object in the Stencil Box. When the dialog box appears, we write "SCRIPT VO Open," since a "script real object" always has to begin with SCRIPT. Inside this script real object, we write the script source code, which is as follows:

VERSION 2
PROLOGUE
SLEEP 1000
APPEAR Example
SLEEP 1000
VOPEN Example
SLEEP 4000
VCLOSE Example
SLEEP 1000
DISAPPEAR Example
END

In ordinary English, what this means is:

This is a program written in Version 2 of MicroScript
Initialize MicroScript interpretation resources
Wait for 1000 milliseconds
Make the virtual object segment Example appear on the screen
Wait for 1000 milliseconds
Open the virtual object segment Example
Wait for 4000 milliseconds
Close the virtual object segment Example
Wait for 1000 milliseconds
Make the virtual object segment Example disappear from the screen
End execution

The above program is pretty simple. All it does is make a virtual object appear on the screen, open it, display the message ("This is how you display, open, and close a virtual object with MicroScript.") for four seconds, close it, and then make it disappear. However, there are two new instructions in the above program, i.e., VOPEN and VCLOSE. These can be used to alleviate the need to open a virtual object on the part of the end user.

Summary

In this lesson and the previous lesson, we discussed the three types of "segments," which are the basic elements, or "actors," in MicroScript programs. These programs are technically referred to as "scripts," and they contain instructions for carrying out "scenes" on the computer screen, which can be thought of as a stage. As we have seen, MicroScript segments are very easy to create, and it is not very difficult to write simple scripts to manipulate these segments.

In order to create MicroScript segments that are more complicated than the ones described in our first two lessons, it will be necessary for the MicroScript programmer to familiarize himself/herself with the appropriate system tools, such as the Basic Figure Editor and the Basic Text Editor. However, since these tools are based on operations that are similar to those of graphic and word processing software software used on other personal computer systems, it should relatively easy to create high quality MicroScript segments after a short period of practice.

The biggest problem in employing MicroScript will probably come when the programmer receives an error message when trying to run a script. The error messages for MicroScript have already been translated and placed in the Appendices section. However, as can be seen, these messages do not go into detail about what went wrong. Since there is sometimes more than one possibility, the programmer should carefully look at his/her script again. Many times the reason a script cannot run is due to a simple error, such as a space occurs where it should not, or there is no space where it should occur. Thus the key to good programming is to pay close attention to what one is doing when one is writing the script for the first time.