Example SenseTalk Scripts


The example scripts presented here are intended to convey the general flavor of the SenseTalk language. No attempt is made to describe the commands used in detail. For the most part they are self-explanatory, or their meaning can be guessed at from the brief explanation preceding each script. Comments within scripts are preceded by a double dash (--).

These examples are all complete, working scripts. However, they do not even begin to illustrate the range of possible applications of the language. For additional examples of the types of things that are possible in SenseTalk, see the sample documents w hich are included with the HyperSense package.


Script of a button that displays the next page in a stack when it is clicked (a "mouseUp" message is sent to an object that is clicked on with the mouse):

on mouseUp	-- (when the mouse button is released over the button)

  go to the next page

end mouseUp	-- (the end of the handler for the mouseUp message)

Script of a button that sorts all of the pages in a stack into ascending order based on the last word in the text of the "Name" field on each page:
on mouseUp

  sort pages by the last word of field "Name"

end mouseUp

Script of a field which redisplays its contents in a long date format (such as "Monday, June 26, 1995") whenever the field is edited (a "closeField" message is sent to a field whenever a user has changed the text in the field):
on closeField

  convert me to long date

end closeField

Script of a field which checks that the contents of the field are a date whenever the field is edited. If the new contents are not a valid date, the script beeps and reselects the text of the field:
on closeField

  if me is not a date then
    beep
    select the text of me
  end if

end closeField

Script of a page which does some initialization each time a user navigates to that page :
on openPage
  
  -- hide our overlays, leaving only the skeleton showing
  hide layer "Organs"
  hide layer "Muscle"
  hide layer "Skin"
  
  -- enable and disable the appropriate buttons
  disable button "Reveal Skeleton"
  enable button "Show Organs"
  enable button "Show Muscle"
  enable button "Show Skin"
  
end openPage

Script of a button that calculates the total of the amounts entered in the "Net Due" field on each page of a stack, when the shift key is not being pressed. If the shift key is held down while the button is clicked, it calculates the average instead of t he total. In either case, the result of the calculation is presented in a small modal panel on the screen. This somewhat contrived example shows the use of multiple message handlers within a single script, and also shows how a handler can send a message to execute another handler :
on mouseUp

  if the shiftKey is not down then
    calculateTotal  -- send a "calculateTotal" message
  else
    calculateAverage
  end if

end mouseUp


-- the next handler is activated by the "calculateTotal" message:

on calculateTotal
  
  put zero into total  -- start our sum at zero
  
  -- now, step through all of the pages in our stack...
  repeat with n = 1 to the number of pages
  
    add field "Net Due" of page n to total
    
  end repeat
  
  -- finally, display the result:
  answer "The total due is " & total
  
end calculateTotal

on calculateAverage  -- handle the "calculateAverage" message
  put zero into total
  
  repeat with each page
    add field "Net Due" of it to total
  end repeat
  
  divide total by the number of pages
  answer "The average amount due is " & total
end calculateAverage

HyperSense | Downloads | Company Info | Main

Send mail to info@thoughtful.com


HyperSense is a registered trademark and SenseTalk is a trademark of Thoughtful Software.
Macintosh, HyperCard, and HyperTalk are registered trademarks of Apple Computer, Inc.