CS 10, Fall 1997 (Section 1)
Lab 5: Scripting with HyperTalk (continued)
The purpose of this lab is to give you more experience with the HyperTalk
language.
Remember to use the book's Appendix as a guide to understanding the HyperTalk
vocabulary.
Assignment for the Next Lab
Write answers to the Review Questions on page 144.
Also write answers to questions 8-10 and 12 on pp 167-168.
These may be handwritten, but prepare to answer them in class and to
turn them in.
Read pages 145-154 before next lab period.
Lab 5 Instructions
- Begin by finishing up lab 4 if you didn't finish it in class
last time. If you weren't able to program the stack to hide the menubar when
the stack is opened, try it again today. Replacing the line show menubar
with
hide menubar in the stack script should do the trick. If you didn't
show us your modified stack last class, call one of us over and show it to us
today.
- Do lab exercise 3 on page 135.
Show what you have written for exercise 3.4 to one of us.
- Now we'll practice scripting with some of the basic HyperTalk material covered in today's reading. Our goal today is to design a simple "greeting card." Begin by creating a new stack containing a single blank card. Add a field to this card and name this field "display." Open the Message box, and enter the following: put "hi" into card field "display" . Press return and observe what appears in the "display" field.
- Enter the following line into the message box: put "hello" into card field "display" . Notice that because we used "into," the contents of the field "display" are replaced with "hello." Now enter the following statement into the message box: put "everybody" after card field "display" . Notice the effect of using the word "after," instead of "into."
- Create a new field on your card. Call this field "name." Somewhere near this field, put some text on your card instructing the user to enter her or his first name in the field.
- Now create a button on your card which will put in the "display" field the words "Hello" followed by the name specified in the "name" field.
- Use a repeat ... with structure to modify the button's script so that it will put "Hello" followed by the appropriate name into each of the first ten lines of the "display" field.
- Add a new field to the card. Modify your button's script so that instead of displaying the above greeting in each of the first ten lines of the "display," it displays the above greeting the number of times specified by whatever number is entered in the field you just created. Make sure that your button erases whatever was previously displayed in the "display" field.
- Call one of us over and show us your "greeting card."
- If you have finished the above exercises and there is still time left, open a new stack. Your task is to create a "Find/Replace" button which behaves similarly to the "Find/Replace" option found in most word processors (refer to Lab 2 if this doesn't sound familiar). Your card will have at least three fields: one field where the user can type in the text which she wishes to edit, another field in which the user can enter the word she wishes to find, and a third field in which the user can enter the word which will replace each occurence of the word specied by the "find" field. Create a button which will carry out this find and replace. If you finish, call one of us over and show us your stack. Notice that what seems like a tedious task for a person to accomplish can be accomplished by a fairly simple script in Hypertalk.
- Consider the flexibility scripting gives you, and think of some simple tasks which you could accomplish with your basic knowledge of Hypertalk. If there is still time left in class, write a script to carry out a task which you think is useful or interesting. If you finish, show us your stack.