Joe Wilkins
Wednesday, February 28, 2007
We left off last week with having pretty much completed a completely new Revolution stack, named the "San Diego Activities and Coloring Book." There were still a number of issues and more than a few scripting challenges to be resolved. I had assumed, somewhat naively, that the balance of the scripts would not be a great deal different than their HyperCard counterparts. As I dug in to completing them, I found that was not exactly to be the case.
Admittedly, Revolution's scripting language, Transcript, is very much like HyperTalk, HyperCard's scripting language. But, in order to create a stack that may be converted to standalone applications for a number of different platforms, it appears that it is necessary to use handlers that may then call different APIs for the various platforms that display that platform's unique objects; whether they be dialogs or other elements that appear on the screen that have their own unique appearances and methods of doing things. This means selecting handler names that belong to Revolution, but may then, based on the particular platform, call APIs from those platforms. This may not be exactly the way it is done, but the most likely. So, we find many of the keywords are prefaced by the letters "rev," the balance of the name being pretty much the same as it would be in HyperTalk, but not always or consistently. Hence, finding the right call is not always that easy. So here is the script that is being used for the button "File" of group "Coloring Book Menu Bar":
on menuPick pWhich
switch pWhich
case "New Coloring Book..."
ask file "Enter Name for new Coloring Book and show where to place it."
if it is empty then exit menuPick
put itemDelimiter into savedDL
set itemDelimiter to "/"
put last item of it into stkName
set itemDelimiter to savedDL
revCopyFile stkName,it
go stack it in a new window
set the name of this stack to quote&stkName"e
set the title of this stack to quote&stkName"e
break
case "Open..."
answer file "Select a Coloring Book to Open" --with type ".rev"
if it is "Cancel" then exit menuPick
go it in a new window
break
case "Close"
hide this stack --it's still open, but not visible
break
case "Save..."
get the long name of this stack --Puts stack name and path into it
revCopyFile (the effective fileName of this stack), it
break
case "Save a Copy..."
answer folder "Select destination folder for backup: "
if the result is "Cancel" then exit menupick
revCopyFile (the effective fileName of this stack), it
break
case "Page Setup..."
answer printer
break
case "Print Current"
set the backcolor of this stack to "white" --So we don't get a grayed backgound printout.
hide group "Coloring Book Menu bar" --We don't want to have the Menu printed.
-- Not all cards have the scrolling color field with it but for erasing color by whiting it
if there is a fld "colorlist" and the visible of fld "colorlist" then
hide fld "colorList"
hide btn "button"
end if
open printing
if thePaperSize is empty then doPrintThisCard (1224,792),72
else print this cd
-- After printing we restore the things we just hid
show group "Coloring Book Menu bar"
if there is a fld "colorlist" and not the visible of fld "colorlist" then
show fld "colorList"
show btn "button"
end if
close printing
break
case "Quit"
put the name of this stack into stkName
delete first word of stkName
answer "Are you sure you wish to Quit "&stkName&"?" with "Cancel" or "OK"
if it is "Cancel" then exit menuPick
quit
break
end switch
end menuPick
on doPrintThisCard thePaperSize,theMargin
-- set up defaults if no size and margin provided:
if thePaperSize is empty then put the printPaperSize into thePaperSize
if theMargin is empty then put 72 into theMargin --72 Pixels per inch
-- get the page area:
set the printMargins to \
theMargin,theMargin,theMargin,theMargin
put theMargin,theMargin, \
item 1 of thePaperSize - theMargin, \
item 2 of thePaperSize - theMargin \
into destinationRect
--print into that rectangle:
print this card into destinationRect
end doPrintThisCard
There are still some aspects of the above script that do not work exactly as I would like; particularly the "New Coloring Book" portion. Note that the backslash character is used to continue the previous statement on the next line; and, in some cases, lines. The scripts are automatically indented and colorized, using the Courier Font. I'm still using the defaults for all of these items, but they CAN be changed to suit the users preferences. Where else to set them than the Preferences menu in the Revolution (Application) menu?

But for the ones I mentioned, you'll need to click on the "Script Editor" in the left column above.

As you can see, there are a whole host of Preferences that you may make your own.
I hadn't really intended to show much, if any, of the scripting for this stack, but I've decided that it is important that you see how similar it is to HyperTalk; so the following is the script that may be found in the Stack's script:
on mousemove
-- To easily reset the cursor by moving the mouse to the top
if the mouseV < 11 then choose Browse tool
end mousemove
on openstack
if the short name of this stack is "About Coloring Book®" \
then exit openstack
global gColor,gCyan,gEveningBlue,gGold,gMagenta,gDarkGreen,\
gYellow, gOrange,gSalmon,gOrchid,gViolet,gBlack,\
gRed,gSpringFrost,gBlue,gWhite
put TheColor() into gColor
repeat with i = 1 to 15
set the checkMark of menuItem i of button "Color" of the \
long name of this stack to (false)
end repeat
set the checkMark of menuitem gBlack of button "Color" of the\
long name of this stack to true
revSpeak "Welcome to " & the short name of this stack
choose browse tool
end openstack
on openCard
if the short name of this stack is not "About Coloring Book®" then
if the number of this cd is 3 or 37 then enable button "Edit"
else disable button "Edit" of the effective name of this stack
if the number of this cd is 11 then
repeat with c = 1 to 15
put "Field "&c into afld
set the foreGroundColor of Field afld to "Red"
end repeat
end if
end if
end openCard
on closeCard
global gCurrentPicture
get the number of this cd
if there is a fld "Music Instructions" and the visible of fld\
"Music Instructions" of cd it then hide fld "Music Instructions" of cd it
if it is 3 then
revStopSpeech
revUnloadSpeech
else if it is 13 or it is 32 or it is 33 or it is 34 then
if gCurrentPicture is not empty then
doHidePict gCurrentPicture
end if
end if
end closeCard
on arrowkey theKey
if target is empty then pass arrowkey
switch theKey
case "up"
go cd 1
break
case "down"
go cd 57
break
case "right"
go next
break
case "left"
go prev
break
case else
pass arrowkey
end switch
end arrowKey
on Enterkey
global gCurrentPicture
get the number of this cd
if it is 13 or it is 32 or it is 33 or it is 34 then
doHidePict gCurrentPicture
end if
end Enterkey
on doShowPict thePict
global gCurrentPicture
if thePict is "Museum of Man" then
put "My Rectangle 2" into theGraphic
put "Picture Title 2" into theFld
else if thePict is "San Diego Museum of Art" then
put "My Rectangle 3" into theGraphic
put "Picture Title 3" into theFld
else if thePict is "Sea World" then
put "My Rectangle 4" into theGraphic
put "Picture Title 4" into theFld
else if thePict is "Mormon National Monument" then
put "My Rectangle 5" into theGraphic
put "Picture Title 5" into theFld
else if thePict is "Lindbergh Field" then
put "My Rectangle 6" into theGraphic
put "Picture Title 6" into theFld
else
put "My Rectangle" into theGraphic
put "Picture Title" into theFld
end if
put thePict into gCurrentPicture
put thePict into field theFld
put " - Click/ENTER Key to close" after field theFld
show graphic theGraphic
show field theFld
show image thePict
put "This izz thee"&thePict into where
if thePict is "La Jolla Cove" then put "This is the "\
& "La Hoya Cove" into where
if thePict is "Cabrillo National Monument" then put \
"This is the " & "Cabreyo National Monument" into where
revspeak where
end doShowPict
on doHidePict thePict
global gCurrentPicture
hide image thePict
if thePict is "Museum of Man" then
put "My Rectangle 2" into theGraphic
put "Picture Title 2" into theFld
else if thePict is "San Diego Museum of Art" then
put "My Rectangle 3" into theGraphic
put "Picture Title 3" into theFld
else if thePict is "Sea World" then
put "My Rectangle 4" into theGraphic
put "Picture Title 4" into theFld
else if thePict is "Mormon National Monument" then
put "My Rectangle 5" into theGraphic
put "Picture Title 5" into theFld
else if thePict is "Lindbergh Field" then
put "My Rectangle 6" into theGraphic
put "Picture Title 6" into theFld
else
put "My Rectangle" into theGraphic
put "Picture Title" into theFld
end if
hide graphic theGraphic
hide field theFld
put empty into gCurrentPicture
end doHidePict
on mouseup
choose browse tool
end mouseup
function TheColor
global gCyan,gEveningBlue,gGold,gMagenta,gDarkGreen,gYellow,gOrange\
,gSalmon,gOrchid,gViolet,gBlack,gRed,gSpringFrost,gBlue,gWhite
put 1 into gCyan
put 2 into gEveningBlue
put 3 into gGold
put 4 into gMagenta
put 5 into gDarkGreen
put 6 into gYellow
put 7 into gOrange
put 8 into gSalmon
put 9 into gOrchid
put 10 into gViolet
put 11 into gBlack
put 12 into gRed
put 13 into gSpringFrost
put 14 into gBlue
put 15 into gWhite
return gBlack
end TheColor
The above script is by no means perfect, and there are a number of things that might be done to improve the handlers it contains, but this will have to do for now. Being at the highest level, some of these handlers are called from other places in the stack; such as the Color Menu - see below.
on menuPick pWhich
global gColor,gCyan,gEveningBlue,gGold,gMagenta,gDarkGreen,gYellow,gOrange,\
gSalmon,gOrchid,gViolet,gBlack,gRed,gSpringFrost,gBlue,gWhite
set the checkmark of menuitem gColor of button "color" to (false)
put empty into gColor
switch pWhich
case "Cyan"
set the checkMark of menuItem gCyan of button "Color" to (true)
put gCyan into gColor
break
case "Evening Blue"
set the checkMark of menuItem gEveningBlue of button "Color" to (true)
put gEveningBlue into gColor
break
case "Gold"
set the checkMark of menuItem gGold of button "Color" to (true)
put gGold into gColor
break
case "Magenta"
set the checkMark of menuItem gMagenta of button "Color" to (true)