Figure 9. Scripting Assignment 1

Preliminary:

First, Create a new stack, get the Message box, and set the userlevel to 5. Make a card button called "SetUp", place it in the center of the card, and open its script (command-option click on the button). The object of the first task is to write a button script for this button that will make a new field, set its properties; then make a button and set its properites. Until you are comfortable with the syntax of all of the commands, the best way to do this is to test each command in the message box, and then, when it works properly, use cut and paste to copy the command into the button script. For example, for a., below, type

doMenu "new field"

in the message box. If the command works properly, copy the contents of the message box (select the text and then command-c), and paste it into the button script (place the cursor, and then command-v). If the command does not do what you want it to, experiment in the message box until you get it right, then paste it into the button script. Note, throughout this assignment, if you ever have trouble accessing the menus you need, reset the userlevel to 5 (especially if you started in one session, and continued in another session).

Instructions how to word each of the commands needed to complete this assignment are found in the Goodman text. Use this as an opportunity to become familiar with this resource. Numbers in square brackets refer to page numbers in Goodman The Complete HyperCard 2.2 (4th ed.).

a. Create a field (use doMenu, and be sure to put quotes around the menu item in your command and use the exact wording from the menu). [See pp. 602-605.]

b. Set the name of the field to "Title" [pp. 573-574]. Remember, you are doing this from the message box, not with the field tool, and that you can refer to the field you just created as "the last card field." (Throughout the assignment, in your scripts or message box, be sure to specify card field, or HyperCard will default to background field and tell you it can't find background field "title")

c. Set the size (rect) of the field [pp. 684-685] to about half the size of the card (hint: you can get the coordinates of the card by typing " the rect of card 1" in message, then experiment with the rect of the field to choose a size you like

d. Position the field in the middle of the card (figure this out from the rect of the card)

e. Put the title "Scripting Assignment No. 1" into the first line of the card field [pp. 474-477].

f. Put your name in the 4th line of the field.

g. Set the font for the field to "Times," the style to "bold" and the fontsize to 23 [see handout on field properties and the appropriate pages in Goodman].

h. Set the properties of the field so that it is opaque, and the lines don't show, and the text is locked.

i. Make the font smaller for the line with your name in it, but not for the rest.

j. Now use doMenu to make a new button. (Note, you can refer to this button as "last button".) Rename it by typing in message box:

set the name of last cd btn to "Next"

k. Set the size of the button to match the size of card (use 'the rect')

l. Hide the name of the button, and make it transparent (set the showName and the style of the button to appropriate values). [See handout on buttons and appropriate pages in Goodman.]

m. Put the following into the script of the card button "Next":

          on mouseUp
go to next card
end mouseUp

As usual, try it first in Message but this eventually will go within your "Set-Up" button script. See the scripts 'Ralph', etc. in our handout illustrating field properties for an example of how to do this. So your command will begin:

	set the script of cd btn "Next" to "on mouseUp" & return ...

This will be longer than the message box is, so type carefully. Peek at the script of the card button to see if you message box command worked properly. Once it does, we'll paste this into the "Set-Up" button script. To copy this whole command (since it is too long to be seen in Message), put the cursor in Message and hit cmd-A to select all, then cmd-C to copy it. Then go back and paste it into the "Set-Up" button script. Once you do this, you will need to add soft returns (option-return). The ampersand (&) is the concatenation operator and 'return' is a carriage return [pp. 821-823 and 830-831].

n. Make a new card (doMenu). Now go back to the first card, and using the regular button and field tools, delete all buttons and fields except the "Set Up" button. Then click on "Set Up" to make sure that everything works.

You will note that the last button is still "selected." You can fix this by adding the the following command to the script for the Set Up button, after the Next button has been created:

choose browse tool

[See Goodman, pp. 504-506.] So the user doesn't have to see all the steps involved here, you should add a line at the beginning of your set up button script to lock the screen [pp. 553-555] before HyperCard creates the field, and unlock it at the end after all steps for making the field and button are complete. (See scripts "Ralph," etc. from the previous class.) In order to test your script, you may have to delete the field and transparant button using the field and button tools (or message box).

Let's add a card script to do all the deletions for us:

		on closeCard
delete card fld "Title"
delete card btn "Next"
end closeCard  

To get to the card script you have two choices: cmd-option-c (which may not work on the library machines) or go to the Objects menu, choose Card Info, and click on "Script" inside its dialog box.

Let's get some practice with a stack script as well. Write a stack script that sets the userlevel to 5 on openStack. (You open the stack script with cmd-option-S.) This is necessary because the New Button and New Field commands are not available unless you are at level 5, and we want this stack to work when the user opens it without having to set the userlevel.

This task teaches you to get the users name, store it in a global variable, and use it in various commands. You may use the appropriate menu tools as needed to do this task, and refer to Goodman on the "ask" and "answer" commands [pp. 549-553]. Make two "handlers" in the script of the second card. The first (on openCard) should use the "ask" command to get your name; and store it in a global variable called "name". Hint: the ask command puts the user's input into the local variable It [pp. 402, 466]. You'll need a command to

put It into name

Do not call it "global name". When you use this global variable, each handler that uses it must have the line:

global name

Remember to end the handler properly.

The second handler (on closeCard) should use the "answer" command to say "goodbye" to you, using your name, and provide an appropriate response button (something, like "See you later" or "Bye, now"). Hints: (a) you will need to declare the same global variable as in the first script; (b) the '&&' operator concatenates (joins) two strings, like '&', but adds a space between them [pp. 821-823]. Now make a button (using the regular menu tools) to take you to the next card; choosing an appropriate icon. Write the script yourself, rather than using authoring tools. Test the button and the scripts. You might want to use the drawing tools to put something on the card, it's kind of dull with nothing there!

Make a third card. Using the regular button tool, make a "Create Field" button that contains a script that makes a new field, names the field, sets its properties, and places several lines of text in it. [The button script will do many of the things you did in Task 1.] Again, using the regular button tools, create a "Delete Field" button that deletes the field. Add several other buttons (with the button tool) that change properties of the field or its text, and that change properties of buttons on the card. [See handout on Field Properties and the appropriate Goodman pages.] You will need to name all of your buttons in order to do the latter. Next to each button, make an "undo" button, puts things back as they were. Experiment with changing properties of specific words or lines in the field. If your button only changes the properties of a portion of your field's text, you must specify which portion to undo [pp. 469-470], e.g.:

set word 2 of line 1 of card fld "text" to plain

Put appropriate navigation buttons on the card for going to the previous and next card. Try to make something interesting out of this, but the primary purpose is to learn field and button properties and to practice writing scripts.

		on mouseUp
end mouseUp