A Better Button Board

Voice Card  -  Volume 12  -  John Card Number 9  -  Thu, Feb 8, 1990 01:46 AM

This is a response to Vol 12 Roger 3 ("Comments button board")...


I am glad to see you dabbling with Hypercard! I will try to remember to send another copy of the button board so that you may examine the scripts.

You ask if it is really necessary to enter 25 different scripts. It is not! Once you grasp the principle of heirarchy, HyperTalk will become much more powerful (and much more fun).

Everything in Hypercard is arranged in a heirarchy. First buttons then cards then backgrounds then stacks. Local tasks that are unique to a particular button should be handled at the lowest level. But whenever a lot of buttons have to do essentially the same thing, a single script at some higher level can handle it. HyperCard first looks at the button, and if the button doesn't know what to do, control automatically ascends the heirarchy. You should strive to do as much of your work as possible at higher levels. This greatly reduces your work, but does sometimes require a little extra cleverness to generalize a set of local tasks.

Each of the 25 buttons on my board has a single word script, and that word is "FLIP". You will note that flip is not part of standard HyperTalk vocabulary. Not to worry! It's easy to add new words to HyperTalk!

When you push one of these buttons, HyperCard encounters the FLIP command and is briefly puzzled. It first searchs through the rest of the button script to see if there's some explanation. Finding nothing, it procedes up the heirarchy. In this case it doesn't have far to go, because the CARD SCRIPT of this one card stack contains a "Handler", that is, a piece of script that begins with the words "On flip". This means, on encountering the command flip, do the following.

In this way, a single script can handle the needs of 25 different buttons (incidentally, there are other ways of achieving this effect). This one script DOES need to know which of the 25 buttons was pushed, but this is easily discovered through the use of the "Target" construct.

I leave it to you to examine this script and PLEASE ask questions about anything that puzzles you. Keep scripting!