BYU Home pageBRIGHAM YOUNG UNIVERSITY
  Humanities Technology and Research Support Center
Back     CHum Revolution Gateway

Computers & the Humanities 210

Messages in Revolution

Objectives

By the end of this reading you should know the following:

  1. Know what a message is.
  2. Be able to name four message that are generated by mouse actions.
  3. Be able to tell when the following messages are sent: openCard, closeCard, preOpenCard, openStack, closeStack, preOpenStack.
  4. Know when an openField message is sent.
  5. Know the difference between closeField and exitField.
  6. Be able to name at least two messages generated by keyboard events.
  7. Understand that you may cause messages to be sent beyond the current handler using the pass and send commands.

What is a Message?

All Revolution programming is based on the concept of messages. When events happen in the Revolution environment, messages are generated and passed through the hierarchy much like a compulsive play-by-play announcer describing everything that happens in the sporting arena. As a programmer, you can write handlers to intercept such messages and subsequently perform different commands and functions. The syntax for utilizing messages sent in Revolution is similar for all:

on <message>   
  <statement(s)>
end <message>
where

<message> is any message generated in Revolution.
<statement(s)> is one or more Transcript statements or commands designed to be associated with the message and subsequently executed.

Mouse Messages

There are several messages associated with mouse clicks:

There are four other messages associated with the mouse. These key on just the cursor and require no click:

Theoretically, these messages can be handled by any object with a proper handler. While this is generally true, reality sometimes paints a different picture. Some of the objects may not handle messages exactly the same as the other objects. You'll have to experiment to discover what works and what doesn't.

Open/Close Messages

Open and close messages are sent when objects are "opened" and "closed"; that is, when they first come into view (as in the case of cards and groups); or receive "focus"; that is when the mouse or keyboard causes them to become the target object (as in the case of fields.) There are four types of objects in Revolution that can utilize these generated messages:

Open handlers are typically used to do initial setup, music, animation, etc., for when the object first appears. Close handlers are typically used to save answers and generally clean up the environment after the current user.

There are a number of supplementary messages related to the opening and closing of objects:

Keyboard Messages

This class of messages is sent to the card (or to the active/focused control) when keys on the keyboard are pressed:

Pass

For most Transcript messages we've talked about, when there is no handler to handle the message as it passes through the hierarchy, it gets ignored. However, there are a few Transcript messages that have a default behavior:

When there is a handler for a message like arrowKey, it intercepts the message and overrides the default behavior. After Revolution has executed a handler, it considers its task finished and the message which triggered the handler consequently dies. In some cases this may be what you want. Writing an arrowKey handler will prevent users from using arrow keys to navigate into parts of your stack you want to keep secure. However, sometimes you actually want Revolution to execute a object's handler and then perform its default behavior or execute another handler located further up in the hierarchy along the message path right after that. To make that happen, you would do something similar to this in the object's script:

on mouseUp   
  beep   
  pass mouseUp
end mouseUp

The pass command tells Revolution to handle the message, then look to the next level of the hierarchy along the message path for a mouseUp handler (be that in a group or a card script). If an appropriate handler is found, it will then execute that handler in the group or card script and stop moving up the levels unless there is also a pass command in that handler.
Note: When the pass command is executed, any remaining statements in the handler are skipped, so this command is best employed at the end of a handler or within an if-control structure.

Send

This command is used to send a message to an object. In this respect it is similar to the pass command. However, with send you can override the normal message path, allowing greater flexibility with where messages are sent. It also differs from pass in that once the command is executed and the message is sent, the rest of the handler is still executed. The basic syntax is:

send <message> to <object>

where
<message> is any message, sent as a literal string.
<object> is any object.

A practical example of this command would look something like this:

on mouseUp
  hide image "flowers"
  send "mouseUp" to button "Reset"   
  show field "Instructions"
end mouseUp

This handler would first hide the image, then send the mouseUp message (it could any given message) to button "reset" (or any other given object). That button would then execute the mouseUp handler in its script. After that had finished, the original handler would continue executing its handler and would show the image. The strength of this command lies in its ability to provide access to handlers in objects outside the normal message hierarchy.

Messages Exercise


Back     CHum Revolution Gateway
Maintained by Devin Asay.
Copyright © 2005 Brigham Young University