Mac and PC On The ST
BY DAVID PLOTKIN
START CONTRIBUTING EDITOR
In the March 1990 issue, I introduced you to Apple's Hypercard, the powerful program which utilizes Hypermedia. The genius behind Hypercard, however, is its built-in programming language, Hypertalk. In this last segment on Hypercard, we'll take a quick look at this impressive language.
Hypertalk is a structured language similar, in some respects, to GFA BASIC and Pascal. It does not use line numbers and contains short blocks of structured code. It can use procedures and user-defined functions, and pass variables. It is, however, very different from other programming languages.
For instance, the syntax rules are extremely flexible: "Go to the first card" is just as acceptable as the more sophisticated "Go to card 1." You can refer to objects by their name, ID, or sequential position. Hypertalk also stores data as a string, converting numbers when necessary, so you don't have to worry about mismatching data types. There is also a variable, It, that automatically receives the result of many commands. Among its numerous commands, Hypercard includes Put (moves text to any position in different fields), Get (recovers any section of text) and Delete. You can Go to cards and Pop back to them, Find text in any field and Send messages.
The Send command is quite useful, since you can Send a message directly to a high-level object (such as a card), bypassing the scripts in lower objects (such as a button) which might otherwise trap your message. The Do command executes the first line of any text field provided that line is a valid Hypercard command. Open lets you launch another Mac application from within Hypercard if you have the memory available. Hypertalk includes Trigonometric (Sine and Cosine) and Transcential (in, Log and Exp) functions for standard mathematical applications.
But there are also some pretty unusual functions, such as a Compound option, which returns the future value of a periodic payment, and Annuity, which returns the present value of one payment. The Value Of function evaluates any formula that has been entered into a field, which essentially lets you write your own spreadsheet in Hypercard. The standard If/Then/Else command is supported in a variety of formats including both single and multiple lines. A command such as Repeat coupled with the command Next Repeat generates any loop conditions that you deem necessary.
|Apple's Hypercard utilizes Hypermedia, a nonlin-
ear database system.
Talking to the Script
Hypertalk speaks to Hypercard through "scripts," small programs written in the language. Every object in a Hypercard stack (buttons, cards, backgrounds, stacks and fields) can hold a Hypertalk script. The mechanics of writing a script are fairly simple. Select the tool for the object you want to modify (i.e., the button tool to modify a button), select the object and choose the script editor. The script editor is not unlike other Mac or ST program editors. A scrollable window lets you see your script and you can type your program into the window, using automatic indenting, cut and paste, and search and replace.
Virtually every application of Hypercard is carried out by a script. For example, click on the Home button to activate its script, which might look something like this: " On MouseUp Go Home End MouseUp." The script checks for the proper condition (that the mouse button has been released) and then executes the command (Go Home). Different conditions can be written into a script; you can make them as long and complex as you like.
Hypertalk follows the established hierarchy of Hypercard objects, the Card, Background, Stack, Home Stack and finally,- Hypercard itself. Your messages move up the line, looking for matching conditions in the scripts of each object. Your command is executed at the level that matches the conditions of your message. This is useful because if you want all the buttons on a card to respond the same way when you press the mouse button, you can put the script in the Card (or the Background, etc.) on up the line, and not have to write a script for each button.
The Final Word
Clearly, Hypertalk is a powerful language in its own right. You will inevitably have to learn it if you are serious about using Hypercard. Unfortunately, Apple's Hypercard documentation does not include any information about Hypertalk. But the language is remarkably easy to learn and there are books available in local retail stores if you want to be a Hyper programmer.