Roger's Wordlist

Wizard Card  -  Volume 8  -  Mr. Wizard Number 1  -  Fri, Aug 25, 1989 1:12 AM

Welcome to the first installment of the NEW IMPROVED Mr. Wizard. When I first created this column, my plan was to produce one wildly improbable stack per month. As you all know, I've only been able to produce two stacks in seven issues.

The irony is that in addition to the improvements and repairs I make on Archipelago each issue, I've also been creating AT LEAST one independent stack per month, most of them of no apparent redeeming value. Although these stacks are not always entertaining, each one serves as an example of what can be done in HyperCard. And each one could provide the basis of a brief HyperTalk tutorial.

So here's the plan. Each month the Mr. Wizard column will feature an original stack by yours truly along with a brief and breezy introduction. I will tell you what the stack does, how it works, how it was constructed, and I will also work in a few basic HyperTalk lessons by focusing on a particular part of the stack. I will add a "Wizard" button to each stack so that you can bounce back and forth between the stack and the introduction. My hope is that even those of you who are not aspiring programmers will gain a greater insight into the magic unfolding "backstage" in each issue of Archipelago.


Our first stack is something I whipped up for Roger during a recent visit. If you are an attentive voice card reader you may recall that Roger is embarking on a very ambitious PONARV: the creation of an artificial language that can express basic concepts and directions clearly and unambiguously with a minimum vocabulary. I hope that as Roger continues his work we can generate a vigorous voice card conversation about the project, so PLEASE ask him lots of questions!

One of his first tasks is to try to come up with a list of about 1500 basic words which can express whatever needs to be expressed. Roger's approach is to comb through a set of basic dictionaries for several small languages and isolate the fundamental concepts from each one. Since his language is not yet invented, he will record these proto-words in English. And since most English words have many meanings, he needs to list each meaning separately.

So he needs some way of keeping track of a growing list of words with multiple meanings from a number of different languages. He needs to avoid duplications and he has to be able to search quickly for words already entered. And it can't take up too much space on the disk.


My solution is a very simple stack that is easy to read and easy to add to. Each English word is given its own card. The word appears in the upper left-hand corner, and beneath it there is room for up to seven different meanings. Each meaning is a candidate for a word in Roger's language and has its own row. There are columns provided for four other languages: Esperanto, Japanese, Tagalog, and Swahili. The overall effect is much like a spreadsheet with five columns and seven rows.

Roger plans to begin by going through existing sources of basic English vocabulary and creating one card per word. He'll look up each word and add row headings for fundamentally different meanings. He'll then scan foreign dictionaries and add foreign words to the appropriate row and column of the word card, adding new rows (or new cards) when necessary. The end result will be a five language concordance of basic words which he can easily search through and sort in any order.

The stack as it now stands is a kind of trial run. Roger was concerned that a thousand card stack would swallow megabytes of disk storage and slow to a snail's pace when searching. As a test of HyperCard's performance, I imported over a thousand different words from the first 3 sections of the Archipelago Help Manual. I installed a very basic set of function buttons that move through the stack and add, drop, sort, and find word cards.

The stack performed beautifully. It only takes up 127K and searching is instantaneous. Adding and deleting words is as simple as pushing a button and the stack automatically prevents duplicate words. Roger claims that he's going to spend the next year or so filling the stack, at which point he will share it with the rest of us and ask us to find words he's missed.


All HyperCard stacks consist of two separate layers, a foreground and a background. The background consists of artwork, buttons, and text fields that are common to all cards. The foreground contains artwork, buttons, and fields that are different for each card in the stack. This is a very powerful scheme which makes it possible to create an entire stack by designing a single background. Roger's WordList has a single background and NOTHING in the foreground, so it was easy to make.

To create the stack I first issued the New Stack command, moved to the background layer (by typing command B), and used HyperCard's painting tools to draw the lines and to paint in the names of the four languages. I also painted in a row of buttons in black and gray across the bottom of the screen. I then added 6 background fields, one for the word and 5 for the 5 columns. When creating the fields I choose the font and spacing so that words typed into the column fields would automatically line up with each other in neat rows and columns.

Next came the 10 background buttons. All ten were transparent overlays that fit over the pre-painted button bar. (Both fields and buttons are created from the New Field and New Button commands in the HyperCard menubar.) The only task remaining was to assign a simple script to each button. And that's all there was to it. I could have done the whole thing in five minutes, but it took more like five hours because I did alot of experimenting before settling on this design.


Now comes the fun part! I want to encourage all of you to get your feet wet by actually peering into the inside of a HyperCard button and reading an actual button script. But first, push the WordList button above and examine the stack. Push all the buttons and see what they do. Add a few cards. Drop a few cards. Play around. (Don't be afraid; this is just a sample stack and you can't do any serious harm.) When you're through push the WIZARD button to return to this card.

Back already? I am now ready to teach you a magic trick. Move to any card in any stack (this one will do) and HOLD DOWN THE OPTION AND CLOVERLEAF KEYS AT THE SAME TIME. You will notice that faint rectangles appear at different parts of the screen and disappear when you let up on the keys. Each rectangle corresponds to a button.

NOW, if you click inside one of these rectangles WHILE HOLDING DOWN THE TWO KEYS, the script for that button will appear in a special edit window. At the lower right corner of the window is a CANCEL button; push that when you are through looking at the script. TRY IT NOW!

A button script (the instructions that tell a button what to do) are created by opening a button's edit window and simply typing in a list of instructions. The instructions are in a remarkable English-like language called HyperTalk.

Your first assignment is to move to the WordList stack and look at the script for the DROP button. As it turns out, dropping a card is quite easy; in fact there is already a Delete Card command in the standard HyperCard menubar. All the drop button does is to issue this command for you so that you don't have to reach up into the Edit Menu.

Actually, it does SLIGHTLY more than that. It's not a good idea to make dropping cards TOO EASY. Whenever you delete information it's a good idea to give the user a chance to change his mind first. So the button politely asks "Are you sure?"

And now, please jump to the WordList stack and have a look at the script...



Here is a copy of the script for the DROP button:

on mouseUp
  answer "Are you sure?"
  with "Yes" or "NO!"
  if it is "NO!" then exit mouseUp
  domenu "Delete Card"
end mouseUp

First question. What is a 'mouseUp'? Every HyperTalk script is triggered by a specific event and button scripts are usually triggered by a human being clicking on the button holding the script. When you click on a button you are actually creating several "events." You push down on the mouse button, you hold it down for a brief time, and then you let up. Each of these is a separate event and the third event is called a mouseUp. When you let up on the mouse, the script is triggered.

Here it is again:

on mouseUp
  answer "Are you sure?"
  with "Yes" or "NO!"
  if it is "NO!" then exit mouseUp
  domenu "Delete Card"
end mouseUp

The button first puts up a little dialog box which asks "Are you sure?" There are two buttons the user can push: Yes and NO! If the user pushes NO! then HyperCard exits the script and nothing else happens. Otherwise the "Delete Card" command is issued and the card vanishes forever. Simple, eh?

And now for your second and final assignment. Go back to the WordList stack and examine the ADD button. Hop to it!



This script is somewhat trickier. Adding a new card is as simple as deleting one, but we want to make sure there are no duplicates. This calls for a bit of cleverness.

As it turns out, every card can have a name of up to 29 letters. What I do in this case is to automatically give each new card the name of the word which appears in the first field. Then, when someone tries to create a new word card I first try to jump to a card with that name. If the card already exists then I jump out of the script. Otherwise I create the new card, put the word into the first field, and name the card. Let's look at the script:

on mouseUp
  ask "New Word?"
  if it is empty then exit mouseUp
  put it into nword
  go to card nword
  if the result is empty
    then exit mouseUp
  domenu "New Card"
  set name of this card to nword
  put nword into field "Word"
end mouseUp

First I ask the user for the new word. If he pushed the cancel button the word will be empty and I'll exit the script. Otherwise I'll store the word in a variable called NWORD and then try to jump to a card named with that word.

If the card already exists and the jump is successful, then "the result" of the jump is "empty" and I exit the script. If not, this must be a brand new word so I go about the business of creating a new word card. I issue the NEW CARD command, I name the card, and I put the word in the upper left hand corner (in field 1). And that's all there is to it!

There! You have now finished your first HyperTalk lesson. I hope you will now start to look inside button scripts ALL THE TIME. You will often be able to figure out what the button is doing even if you've never programmed before. IT'S FUN! IT'S EASY! IT'S SATISFYING!

PLEASE PLEASE PLEASE ask me questions on voice cards about this stuff. What do you find confusing about HyperTalk? What can I do to make this column more useful and interesting? How could Roger's stack be improved? What buttons have you peeked at? What would YOU like to do with HyperCard?

Stay tuned for more exiting HyperTalk lessons from Mr. Wizard!