Home
The HyperCard Center
HyperTalk Reference
Home » HyperTalk Reference » HyperTalk basics

Note: This is a work in progress and will be formatting errors. Read more about the project on the home page.

Writing message handlers

When you write a handler for a message, you specify a sequence of statements for HyperCard to run. Each message handler has the following form, with the italicized words as placeholders:

on messageName
    statements
end messageName

When it runs the message handler, HyperCard sends each line of the handler as a message itself (so handlers can call other handlers).

Important: The message name does not have to be one of HyperCard’s built-in system messages or commands.

For example, if you wanted a new command called doubleBeep that would beep twice, you would write a handler for it as follows:

on doubleBeep
   beep
   beep
end doubleBeep

Of course, HyperCard doesn’t know about the doubleBeep command, so it will never be sent automatically in response to an event. But you can send doubleBeep from the Message box or use it as a statement in other handlers.

For example, the script of a card button might contain the following handler for the system message mouseUp:

on mouseUp
  doubleBeep
end mouseUp

If the script also contains the doubleBeep handler (or if the script of any object later in the message-passing path contains it), the mouseUp message will send the doubleBeep message, and doubleBeep will send two beep commands. Because beep is a built-in command, HyperCard beeps twice.

If HyperCard can’t find the doubleBeep message, it will complain (with a dialog box) that it “can’t understand” the message.


Placeholders

messageName
Any text string, without quotation marks, that represents the name of the message handler you want to write:

calculateDebt
selectWholeLine
As in:
on calculateDebt
on selectWholeLine theLine, aContainer


statements
Any return-separated list of built-in commands, user-defined handlers, or keywords that are part of a message or function handler.

put "Hello world"   -- built-in command
get total(field 1)  -- function call
global HelpInfo     -- keyword


Related Topics

« The message-passing order | HyperTalk Reference | Using parameter variables »

Version 0.7b1 (March 24, 2022)

Made with Macintosh

Switch to Retro View