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:
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.
In ordinary English, what this means is:
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.
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:
In ordinary English, what this means is:
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.
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.