CS 10, Fall 1997

Lab 4: Scripting with HyperTalk


The purpose of this lab is to introduce you to the HyperTalk language for programming HyperCard stacks. Refer to pages 379-384 of the Appendix for a summary of the HyperTalk vocabulary.

Assignment for the Next Lab

Read pages 124-144 before next lab period. Answer the review questions on page 135 (for exercise 2, assume sum = 14). Note that the function exp2(n) returns 2 to the power n, so exp2(3) returns 8. Write the answers down, as you will be asked to submit them. (These can be hand-written.)

Lab 4 Instructions

  1. Copy module4 from the Classes file server to your disk. Remember to drag the file server icon to the trash once you've copied today's files.

  2. Begin with lab exercise 1 on page 121.

  3. When you have finished lab exercise 1, open a new copy of the stack "No Account." We want to add a new card to this stack which will have a different background from the current one. To do this, create a new background. This automatically creates a new card with this background.

  4. Create a field on this card that says "Welcome to stack "No Account" "

  5. Modify the stack's script so that when the stack is opened, the first card which appears is the card you just created.

  6. Add a button to the new card which will save a copy of this stack.

  7. Add a button to the new card which will link it to the original card. In the script for this button, identify the card to be linked to by its number (not ID or name).

  8. Modify the stack's script so that when the stack is opened, the menu bar disappears.

  9. Add a button to the "welcome" card which will display the menubar.

  10. Add a line to the stack's script so that the "welcome" field is locked when the stack is opened.

    When you have finished, call one of us over to show us your changes.


Hypertalk Syntax

Syntax statements show the most general form of a command or function with all the elements in the correct order. The syntax statements shown below use the following typographic conventions. Words or phrases in this kind of type are Hypertalk keywords that you type exactly as shown. Square brackets [ ] enclose optional elements that may be included if you need them. (Don't type the brackets.) Emphasized words are placeholders describing general elements, not specific names. For example, effectName stands for any of the Hypertalk visual effect names, such as barn door, checkerboard, or zoom out.

Some Commands

go [to] stack
go [to] card [of stack]
go [to] background [of stack]

put expression
put expression into container

set [the] property to expression
set [the] property of object to expression

show button
show field

hide button
hide field

Some Functions

exp2(number)
average(list of numbers)
sqrt(number)

length(text)

date()
time()

Some Operators

Numeric: *, /, +, -, ^
Comparison: >, <, <=, >=, <>, =
Logical: not, and, or

Some Properties

Global: userLevel, cursor
Button: hilite, icon, name, visible
Field: lockText, scroll, showLines, visible