home *** CD-ROM | disk | FTP | other *** search
/ The Ultimedia System / IBM_ACD_101.ISO / tbkeval / oworkbk.tbk (.txt) < prev    next >
Asymetrix ToolBook File  |  1992-01-28  |  266KB  |  3,369 lines

  1. Advanced topics
  2. Advanced topics
  3. startSection
  4. sectionNumber
  5. OpenScript applications
  6. OpenScript applications
  7. startSection
  8. sectionNumber
  9. -- When a chapter 
  10. clicked update the section list.
  11. 4s_DidDoubleClick
  12. updateSectionList
  13. oselectedTextLines
  14. strip(
  15. -- If 
  16. user presses a key that 
  17. reflect 
  18. -- Algorithm:
  19. -- Get 
  20. currently 
  21. . Forward 
  22. keystroke 
  23. ToolBook 
  24. default processing. Check 
  25. -- changed. If so, 
  26.  message 
  27. sections.
  28. causes 
  29. respond 
  30. -- Update 
  31. 4s_currentSection
  32.     -- Set 
  33. "Chapter 
  34. 3Name" 
  35. "Sections" 
  36. commandLine 
  37. sectionList 
  38. " && "
  39.     -- Clear 
  40. buttonDoubleClick
  41. buttonUp
  42. keyDown
  43. updateSectionList
  44. buttonUp
  45. updateSectionList
  46. s_DidDoubleClick
  47. buttonDoubleClick
  48. strip
  49. s_DidDoubleClick
  50. keyDown
  51. updateSectionList
  52. updateSectionList
  53. Chapter Name
  54. strip
  55. set sectionList to
  56. Sections
  57. of this page
  58. Sections
  59. Sections
  60. sectionList
  61. commandLine
  62. s_currentSection
  63. Title
  64. E v a l u a t i o n   E d i t i o n
  65. E v a l u a t i o n   E d i t i o n
  66. Welcome
  67. uy ToolBook
  68. default
  69. default
  70. Title
  71. myAuthor
  72. myAuthor
  73. author
  74. OpenScript Workbook
  75. OpenScript Workbook
  76. -- Animate the message spark through 
  77. hierarchy 
  78. Hsending 
  79. -- moveLSpark 
  80. /. The 
  81. Ualong which 
  82. travel.
  83. showMe
  84. 4s_flag
  85. \"et1"
  86. f"et2"
  87. p"et3"
  88. "et4"
  89. "et5"
  90. done 
  91. following 
  92. handlers are used 
  93. asure 
  94. user 
  95. prompted 
  96. example 
  97. "Show Example" 
  98. Bhas 
  99. xbeen clicked but
  100. Rtries 
  101. leave 
  102. StrTryMsg() 
  103. fStrShowDemo() 
  104. StrNoDemo()
  105. SysLockScreen 
  106. leaving 
  107. && "can 
  108. %animated examples 
  109. && "messages 
  110. sent 
  111. . You normally"\
  112. && "trigger each demonstration 
  113. Hclicking 
  114. && """
  115. Bon that 
  116. Would 
  117. like 
  118. see the"\
  119. instead 
  120. moving on 
  121. "&No 
  122. rPage
  123. showMe
  124. enterPage
  125. leavePage
  126. rTryMsg
  127. StrShowDemo
  128. StrTryMsg
  129. StrNoDemo
  130. showMe
  131. moveLSpark
  132. moveLSpark
  133. moveLSpark
  134. moveLSpark
  135. moveLSpark
  136. s_flag
  137. enterPage
  138. s_flag
  139. StrTryMsg
  140. StrShowDemo
  141. StrNoDemo
  142. StrShowDemo
  143. Show Example
  144. buttonDown
  145. buttonUp
  146. s_flag
  147. leavePage
  148. s_flag
  149. StrTryMsg
  150. The page you are leaving and the following pages
  151. can show you animated examples of how
  152. messages are sent along the hierarchy. You normally
  153. trigger each demonstration by clicking the yellow
  154. "Show Example" button on that page.  Would you like to see the
  155. demo for this page instead of moving on to the next page?
  156. StrShowDemo
  157. &Show Example
  158. StrNoDemo
  159. &No Demo
  160. The Pattern Property
  161. Background Objects
  162. Mouse movement and button messag
  163. To get and To set Handlers
  164. Book Editor
  165. Local versus System Variables
  166. Branching with If/then/else
  167. Branching control structures
  168. User-defined messages 1
  169. Expressions
  170. sectionNumber
  171. startSection
  172. Expressions
  173. An expression is a way of combining or specifying values in OpenScript. For example, the following are expressions:
  174. 125 + 77
  175. (text of field "Cost" - 5)
  176. An expression has a result. The result of the first expression is 202. The result of the second expression depends on the contents of a field named "Cost."""eld named "Cost."
  177. Using the debugger to interrupt 
  178. sectionNumber
  179.     A looping control structure whose ending condition is never met is called an endless loop. If you run a handler that contains an endless loop your computer may appear broken. Fortunately, you can interrupt a running handler so you can edit the script and fix it.
  180. 1.    Switch to Reader level.
  181. 2.    Click the "Endless Loop" button.
  182.     This button's script contains an endless loop.
  183. 3.    Hold down both Shift keys until the Debug window appears.
  184. 4.    To return to ToolBook, choose Exit Debugger from the Options menu.
  185.     To find out more about how to use the Debug window, see ToolBook Online Help.g Scripts," in Using OpenScript.
  186. Using Shift+Shift to interrupt an endless loopp
  187. Endless Loop
  188. -- This handler 
  189. endless loop. The 
  190. _tests
  191. -- i 
  192. will 
  193. 'than 
  194. equal 
  195. zero. However,
  196. -- i starts 
  197. increases so the ending condition 
  198. -- never met. Press Shift+
  199. -- running 
  200. interrupt 
  201. TDebug 
  202. ci > 0
  203. buttonUp
  204. buttonUp
  205. Endless Loop
  206. Types of expressions
  207. Types of expressions
  208. There are three types of expressions in OpenScript:
  209. numeric        Results in a number (e.g. 10 / 3 = 3.33333333)
  210. string            Results in a string 
  211.                 (e.g. "Cat" & "Mouse" = "CatMouse")
  212. logical        Results in true or false (e.g. 6 > 11 = false)
  213. The following exercises allow you to explore writing expressions and predicting their results.lts..
  214. sectionNumber
  215. Building expressions
  216. sectionNumber
  217.     An expression consists of one or more values separated by operators like +, -,     &&, 
  218.     and so on. For example, "100", "100+5", 
  219.     and "3>5 or 5>3" are all expressions.
  220. 1.    Switch to Reader level.
  221. 2.    Use the lists of values and operators to the right to build an expression. Click the values or operators you want in your expression. They will be added in the order you click them. You can also type directly in the "Expression" field.
  222. 3.    Predict the result of your expression, then click the "Show Result" button to see your expression's result in the "Result" field."Result" field......... in the "Result" field... the "Result" field....................
  223. Building expressions_
  224. -- If the current expression has already been calculated, 
  225. ;"Expression" 
  226. "Result" fields. In 
  227. M, place 
  228. pselected value 
  229. lineNum 
  230. <= 0; 
  231. W& " " 
  232. buttonUp
  233. buttonUp
  234. Expression
  235. Result
  236. textFromPoint
  237. Expression
  238. lineNum
  239. calculated
  240. 1.0e5
  241. false
  242. "Avacado"
  243. "Beet"
  244. "Carrot"
  245. "Eggplant"
  246. "Zucchini"
  247. -- Add the selected operator 
  248. expression.
  249. 4calculated
  250. "Expression"
  251. "Result"
  252. lineNum 
  253. <= 0; 
  254. " " & 
  255. W& " " 
  256. buttonUp
  257. buttonUp
  258. Expression
  259. Result
  260. textFromPoint
  261. Expression
  262. lineNum
  263. calculated
  264. is not
  265. contains
  266. is not in
  267. Value:
  268. Operator:
  269. Result
  270. Expression
  271. Expression:
  272. Test Result
  273. Result:
  274. Show Result
  275. -- Use the 
  276. function 
  277. expression 
  278. "Expression"
  279. . If there 
  280. error, display a 
  281.  message, otherwise, place 
  282. |result 
  283. "Result" 
  284. 4calculated
  285.     -- The following 
  286. Uputs 
  287. _succedes 
  288. 's syntax 
  289. handler can 
  290. . Trying 
  291. invalid 
  292. results 
  293. "Execution Suspended"
  294. "Test 
  295. " && 
  296. "This isn't a correct 
  297. . Remember," && \
  298. consists 
  299. values separated" && \
  300. Hoperators."
  301. buttonUp
  302. buttonUp
  303. Expression
  304. Test Result
  305. set a to
  306. Result
  307. This isn't a correct expression. Remember,
  308. an expression consists of values separated
  309. by operators.
  310. expression
  311. calculated
  312. Show Result
  313. Specifying parts of strings
  314. sectionNumber
  315.     You can refer to parts of strings in OpenScript.
  316.     For example, if you want characters two through
  317.     five of the string in the field to the
  318.     right you would type:
  319.     characters 2 to 5 of text of field "String"
  320.     If you want just character 10 you
  321.     would type:
  322.     character 10 of text of field "String"
  323.     To specify words use "word" rather 
  324.     than "character."
  325. 1.    Switch to Reader level then  
  326.     specify words 3 through 5 of the 
  327.     string by typing an expression in the
  328.      "String Specifier" field. Click the 
  329.     "Show Result" button to see the expression's result. Make up some other expressions and try them..
  330. Specifying parts of strings
  331. String
  332. The quick brown fox jumped over the lazy dogs.
  333. String:
  334. Show Result
  335. -- Use the 
  336. function 
  337. specifier
  338. ""String Specifier" 
  339. . If there 
  340. error display a
  341. message. Otherwise, place 
  342. result 
  343. "Result" 
  344. sSpecifier 
  345.     -- The following 
  346. Uputs 
  347. _succedes 
  348. 's syntax 
  349. handler can 
  350. . Trying 
  351. invalid 
  352.  results 
  353. "Execution Suspended"
  354. "Test 
  355. " && 
  356. "This isn't a 
  357. buttonUp
  358. buttonUp
  359. String Specifier
  360. Test Result
  361. set a to
  362. Result
  363. This isn't a valid string specifier. Try again.
  364. sSpecifier
  365. Show Result
  366. String Specifier
  367. characters 5 to 15 of text of field "String"
  368. String Specifier:
  369. Result
  370. quick brownnown fox jumped over the lazy dogs.
  371. Test Result
  372. "String"
  373. String
  374. Result:
  375. -- Table 
  376. Contents - 
  377. -- The 
  378. may be entered 
  379. 8. That 
  380. 's section 
  381. saved 
  382. -- s_currentSection 
  383. handler. 
  384. used 
  385. displayed.
  386. -- There 
  387. also a 
  388. -- marks a completed 
  389. chapter 
  390. Hplacing 
  391. -- asterisk beside its 
  392. -- When entering 
  393. (entry 
  394. -- corresponding 
  395. recorded 
  396.     -- Switch 
  397. Reader level
  398.     -- Hide 
  399. help 
  400.     -- Highlight 
  401. selectedTextLines 
  402. J"Chapters" 
  403. J"Sections" 
  404. -- Place 
  405. front 
  406. identified 
  407. x. If 
  408. sections 
  409. , place 
  410. markSection x
  411. chapterNum 
  412. sectionNum 
  413.         -- Get 
  414. list 
  415.         -- 
  416. propertyName 
  417. commandLine 
  418. " && 
  419. 5&& "
  420.         -- 
  421. fore 
  422. " && 
  423.         -- If 
  424. chapterDone 
  425. chapters 
  426. x"*" 
  427. enterPage
  428. markSection
  429. enterPage
  430. reader
  431. Chapters
  432. buttonUp
  433. Chapters
  434. Sections
  435. Sections
  436. currentSection
  437. s_currentSection
  438. markSection
  439. Sections
  440. of page "Table of Contents"
  441. of page "Table of Contents" to it
  442. Chapters
  443. Table of Contents
  444. chapters
  445. chapterDone
  446. commandLine
  447. propertyName
  448. sectionNum
  449. chapterNum
  450. Chapter Head
  451. Using the workbook
  452. Basic concepts
  453. Basic concepts
  454. startSection
  455. sectionNumber
  456. Elements of OpenScript
  457. Elements of OpenScript
  458. startSection
  459. sectionNumber
  460. OpenScript commands
  461. OpenScript commands
  462. startSection
  463. sectionNumber
  464. enterPage
  465. enterPage
  466. Lists
  467. Lists
  468. A list contains items which are separated by commas. For example, the following list contains four items:
  469. Oranges, Apples, Star Fruit, Kiwi
  470. Notice that even though "Star Fruit" is two words it is only one item since it is between commas. The following exercise allows you to experiment with lists and items....you to experiment with lists and items.....
  471. startSection
  472. sectionNumber
  473. Lists
  474. Changing an Object's Color Prope
  475. The sysCursor Property
  476. OpenScript Workbook
  477. Listing Objects using Push and P
  478.  on a Page
  479. Table of Contents
  480. Close the Workbook
  481. bjects from 
  482. Handling Standard Menu Choices
  483. Handlers in Backgrounds
  484. Table of Contents
  485. The OpenScript Workbook
  486.  1991 Asymetrix Corporation 
  487. All Rights reserved.
  488. Asymetrix OpenScript Workbook Team:
  489. Bob Gallup
  490. Carol Buchmiller
  491. Claude Ostyn
  492. Greg Pearson
  493. Brad Gaub
  494. Tom Arnold
  495. instructional design:
  496. Tec Ed, Ann Arbor, Michigan
  497. ichigan
  498. ructional design:
  499. Tec Ed, Ann Arbor, Michigan
  500. -- Go 
  501. the Table 
  502. Contents 
  503. buttonUp
  504. buttonUp
  505. Table of Contents
  506. Table of Contents
  507. Showing all objects on a page
  508.     If you want to show all objects on a page even if they are currently hidden, you can use the page's objects property.
  509. 1.    To show all objects on a page, type the following command in the Command window:
  510.     show objects of this page
  511.     This technique can be useful if you know there are hidden objects on the page but you don't know their names or IDs.
  512.     How would you hide the objects on this page? How would you show all objects on the background?
  513. Showing all objects on a page
  514. Button
  515. sectionNumber
  516. OpenScript Workbook
  517. January, 1991
  518. (c) Asymetrix Corporation
  519. gives you permission 
  520. e, revise 
  521. reuse the individual 
  522. scripts 
  523. your own applications.
  524. --You may 
  525. x, however, 
  526. Sentire 
  527. a substantial part 
  528. redistribution 
  529. jproduct.
  530. retains 
  531. copyright on 
  532. original elements 
  533.  . Include 
  534. notice "Portions 
  535.  are 
  536. they contain 
  537. copied 
  538. -- Special handling 
  539. Author 
  540. test drive version
  541. -- It does 
  542. xstop 
  543. clock, but prevents annoying messages
  544. -- due 
  545. frequent 
  546. cdoing 
  547. exercises 
  548. myAuthor 
  549. "Title" 
  550. "Welcome"
  551. -- When entering 
  552. 8, switch 
  553. Reader level, 
  554. -- environment, 
  555. cbar 
  556. status box.
  557. 4s_launchedFrom, s_changesDB, s_currentSection
  558. restoreEnvironment
  559. done 
  560. "The hierarchy 2" 
  561. leaving 
  562. -- Restore 
  563. _saving 
  564. contents
  565. . Also, 
  566. asure that
  567. -- ToolBook confirms 
  568. user exits 
  569. 8without
  570. -- System 
  571.     - Application 
  572. workbook
  573. setting 
  574. nproperty
  575. --            
  576. 8was opened
  577. FromAppSampler
  578. oldLaunchedFrom 
  579. oldFromAppSampler 
  580. sFromAppSampler
  581. oldChangesDB 
  582. beginning 
  583. a section,
  584. . If 
  585. marks 
  586. L list.
  587. -- This handler also unlocks 
  588. screen, forcing 
  589. image, 
  590. mouse cursor 
  591. hourglass 
  592. default shape.
  593. scomplements 
  594. , which 
  595. effective 
  596. notify 
  597. flipping 
  598. complete.
  599. 4s_sectionStarted
  600. sectionNumber 
  601. startSection 
  602. markSection 
  603. /"Table 
  604. Contents"
  605. record 
  606. Exit 
  607. selected 
  608. sent 
  609. Command 
  610. started 
  611. . If so, 
  612. Tour.
  613.     linkDLL "tbkwin.dll"
  614.         STRING GetWinIniVar(
  615. OldBook 
  616. ","AppSampPath")
  617. "Unable 
  618. G    New 
  619. , issue a warning 
  620.  creating a 
  621. 8will 
  622. -- impossible 
  623. "Creating a 
  624. Pmean 
  625. can't 
  626. " && \
  627. unless 
  628. directly." \
  629. f"Create" 
  630. "Cancel"
  631.  opening a 
  632. "Opening a 
  633. " && \
  634. -- Use 
  635. function 
  636. asterisk, 
  637. strip x
  638. SPACE & TAB & "*" & CR & LF
  639. restoreEnvironment
  640. enterPage
  641. author
  642. leavePage
  643. leaveBook
  644. enterBook
  645. strip
  646. author
  647. myAuthor
  648. Title
  649. Welcome
  650. enterBook
  651. reader
  652. eRrestoreEnvironment
  653. sizeToPage
  654. The hierarchy 2
  655. s_launchedFrom
  656. s_changesDB
  657. s_currentSection
  658. leaveBook
  659. eRrestoreEnvironment
  660. s_changesDB
  661. restoreEnvironment
  662. oldChangesDB
  663. oldFromAppSampler
  664. oldLaunchedFrom
  665. s_launchedFrom
  666. s_changesDB
  667. sFromAppSampler
  668. enterPage
  669. sectionNumber
  670. startSection
  671. sectionNumber
  672. markSection
  673. Table of Contents
  674. default
  675. s_sectionStarted
  676. leavePage
  677. sectionNumber
  678. s_currentSection
  679. tbkwin.dll
  680. GetWinIniVar
  681. ToolBook
  682. AppSampPath
  683. GetWinIniVar
  684. AppSamp.tbk
  685. Unable to return to the Application Sampler.
  686. OldBook
  687. sFromAppSampler
  688. Creating a new book will mean you can't return
  689. to the Application Sampler unless you open it directly.
  690. Create
  691. Cancel
  692. Cancel
  693. sFromAppSampler
  694. Opening a new book will mean you can't return
  695. to the Application Sampler unless you open it directly.
  696. Cancel
  697. Cancel
  698. sFromAppSampler
  699. strip
  700. Popping items from a list
  701. sectionNumber
  702.     The objects property of a page, background, or group returns a list of object references. The object property of an object is the object's type (e.g. the object of ellipse id 42 is ellipse). Using the pop command and the objects and object properties, you can write a handler to count the number of objects of a certain type on a page.
  703. 1.    Create a button called "Count Ellipses"
  704. 2.    Write a handler that gets the objects property of this page. Then, using the pop command, count the number of objects that are ellipses.
  705.     Switch to Reader level and click the "Hint" button for one solution.
  706. 3.    How could you count all the rectangles on the page?
  707. Popping items from a listttttttttttter o
  708.  to handle buttonUp
  709.         set numEllipse to 0
  710.          get objects of this page
  711.         while it is not null
  712.             pop it into anObject
  713.             if object of anObject is "ellipse"
  714.                 increment numEllipse
  715.             end
  716.         end
  717.         put "Number of ellipses is" && numEllipse
  718. end buttonUp
  719. -- Show 
  720. the hint.
  721. "Hint"
  722. buttonUp
  723. buttonUp
  724. Accessing items in lists
  725. sectionNumber
  726.     Many properties are lists. For example, fillColor, strokeColor and bounds are all lists. In this exercise you will see how to change an item in an object's bounds to change the object's height.
  727. 1.    Look at the script in the button "Shorten Pyramid."
  728.     Double-click the button while pressing the Ctrl key. Notice which item of the pyramid's bounds is modified by the script.
  729. 2.    Switch to Reader level and click several times on the "Shorten Pyramid" button. What happens?
  730. 3.    Create a new button called "Grow Pyramid" and write a buttonUp handler to make the pyramid taller by moving the bottom of the pyramid down...............
  731. Accessing items in lists
  732. Shorten Pyramid
  733. Pyramid
  734. -- Make the 
  735. "e" shorter 
  736. units 
  737. Hincrementing 
  738. =. The 
  739. -- corresponds 
  740. (y coordinate) 
  741. Ledge.
  742. "pyramid"
  743. buttonUp
  744. buttonUp
  745. pyramid
  746. pyramid
  747. Using OpenScript Help
  748. 226,280
  749. SetWinHelpDims
  750.     -- Adjust 
  751.  .ini settings 
  752. xrunning yet, so that 
  753. will come 
  754. )a good
  755. OpenScript 
  756. Kbar 
  757.     -- below default 
  758. OWorkBk 
  759.     -- Note: Assumes most common 
  760. M,which 
  761. standard VGA,
  762.  3.0 
  763.  compatibility.
  764.     linkDLL "tbkwin.dll"
  765.         WORD SetWinIniVar(STRING,
  766. "Windows 
  767. ","Xl","27")
  768. ","Yu","37")
  769. ","Xr","611")
  770. ","Yd","475")
  771. ","Maximized","0")
  772. enterpage
  773. SetWinHelpDims
  774. enterpage
  775. SetWinHelpDims
  776. SetWinHelpDims
  777. tbkwin.dll
  778. SetWinIniVar
  779. Windows Help
  780. SetWinIniVar
  781. Windows Help
  782. SetWinIniVar
  783. Windows Help
  784. SetWinIniVar
  785. Windows Help
  786. SetWinIniVar
  787. Windows Help
  788. Maximized
  789. SetWinIniVar
  790. sectionNumber
  791.     In this exercise you will display and explore OpenScript Help. Follow the steps below. Please read all the instructions before starting.
  792. 1.    Activate the Command window.
  793.     Display the Command window by pressing Shift+F3. You can move the Command window by dragging its caption bar. If the Command window is already visible, click it to activate it.  
  794. 2.    Display OpenScript Help: Press the F1 key.
  795. 3.    Click "Using this Encyclopedia" in the index and read the text displayed. Return to the index and explore other terms of interest. When you are finished, close OpenScript Help by double-clicking its Control menu.
  796.     For information about using Windows help itself, choose "Using Help" from the Help menu in OpenScript Help.
  797.  Help.
  798. Using OpenScript Help
  799. What this book contains
  800. What this book contains
  801. This book contains exercises and examples to help you learn to use OpenScript for writing scripts. The book is divided into chapters and sections. Each section covers one topic and contains a mix of explanation and exercises. 
  802. Chapter
  803. Explana-
  804. Exercise
  805. Explana-
  806. Exercise
  807. Section
  808. Section
  809. startSection
  810. sectionNumber
  811. User-defined functions 2
  812. ontinue
  813. User-defined functions, continued
  814. sectionNumber
  815. The following OpenScript command uses the isAlpha function to set the variable charType to true or false:
  816. set charType to isAlpha(char 2 of name)
  817. If a function is not defined in the same script as the handler that refers to it, ToolBook follows the object hierarchy looking for a corresponding to get handler.r.ect hierarchy looking for a matching to get handler.ndler..ollows the object hierarchy to find a matching to get handler.
  818. Object Types
  819. OpenScript Help
  820. Clicking a page
  821. Writing a Simple buttonUp handle
  822. Restoring Menus
  823. Listing objects, continued
  824. .    Toolbook programming
  825. To set handler continued
  826. ith a 
  827. sectionNumber
  828. 1.    Read about to set handlers in OpenScript help.
  829. 2.    Write a to set handler to set a property called objectSize of the green ellipse to the right. Place the handler in the ellipse's script.
  830. 3.    Test the handler from the Command window by typing:
  831.     set the objectSize of ellipse "green" to 2000, 500
  832.     To see one solution, switch to Reader level and click the "Hint" button.r level and click the "Hint" button..
  833. To set handler, continuedwith a To Set Handler, cont.
  834. green
  835. -- Get and Set handlers for the size property.
  836. -- Place them in an object's script.
  837. to set objectSize to xyList
  838.     get my bounds
  839.     set item 3 of it to item 1 of it + item 1 of xyList
  840.     set item 4 of it to item 2 of it + item 2 of xyList
  841.     set my bounds to it
  842. to get objectSize
  843.     get my bounds
  844.     clear theSize
  845.     push item 4 of it - item 2 of it onto theSize
  846.     push item 3 of it - item 1 of it onto theSize
  847.     return theSize
  848. -- Show 
  849. the hint.
  850. "Hint"
  851. buttonUp
  852. buttonUp
  853. Branching control structures
  854. ranching
  855. If/then/else and conditions/when/else are ToolBook's branching control structures. If/then/else provides two-way branching and Conditions/when/else provides many way.....vides many way.....
  856. to handle buttonUp
  857.     ask "What's your name?"
  858.     if it is not null then
  859.         set text of field "Name" to it
  860.     else
  861.         beep 10
  862.     end if
  863. endep 10
  864.     end if
  865. to handle buttonUp
  866.     request "How Hot?" with "Mild" or \
  867.         "Medium" or "Hot"
  868.     conditions
  869.         when it is "Mild"
  870.             set spice to 0
  871.         when it is "Medium"
  872.             set spice to 5
  873.         else
  874.             set spice to 10
  875. If/then/else:
  876. Conditions/when/else:
  877. sectionNumber
  878. Branching control structuresgggggggggggg
  879. User-defined functions 1
  880. ntinue
  881. User-defined functions, continued
  882. An example of a user-defined function is:
  883. to get isAlpha testChar
  884.     return testChar is in "abcdefghijklmnopqrstuvwxyz" 
  885. The name of this function is "isAlpha". It has one parameter, "testChar". The return command sets the function's value to true it testChar is a letter or false if it is not.
  886. tter.
  887. Sets the variable charType to true or false
  888. sectionNumber
  889. Looping control structures
  890. sectionNumber
  891. Looping control structuresgggggggggg
  892. Step, do/until, and while are ToolBook's looping control structures......tep            - repeats 
  893. to handle buttonUp
  894.     step i from 1 to 10
  895.         set fieldName to "field " & i
  896.         clear the text of field fieldName
  897. end1 seconds
  898. end    beep 10
  899.     end if
  900. Step:
  901. to handle buttonUp
  902.     set giveAccess to false
  903.     while not giveAccess
  904.         ask "Password"
  905.         if it is securityCode of this book then
  906.             set giveAccess to true
  907.         end if
  908. endndnd
  909. While:
  910. to handle buttonUp
  911.         pop objectList
  912.         show it
  913.     until objectList is null
  914. endd"
  915.     if it is securityCode of this book then
  916.         put true into giveAccess
  917.     end if
  918. Do/until:
  919. The sysCursor property
  920. sectionNumber
  921.     The ToolBook system also has properties. They are called system properties. One of many useful system properties is the sysCursor property which can be used to change the shape of the mouse pointer.
  922. 1.    The "Please Wait" button contains the script displayed at the bottom of the page. Look at the script and try to identify the commands that change the sysCursor property.
  923. 2.    Switch to Reader level and click the button to see how the cursor shape is changed.
  924. 3.    Look up sysCursor in OpenScript Help and edit the button's script to try some of the other cursor shapes.....ursor shapes. shapes..es..s.rsor shapes..
  925. The sysCursor property
  926. Please Wait
  927. -- Set the cursor 
  928. hourglass 
  929. default shape.
  930. buttonUp
  931. buttonUp
  932. Please Wait
  933. -- Shows setting the cursor to a different shape
  934. to handle buttonUp
  935.     set sysCursor to 4
  936.     pause 3 seconds
  937.     set sysCursor to 1
  938. Handlers in backgrounds
  939. sectionNumber
  940. If neither the object nor the page has a buttonDown handler, but the background does, the background handler gets executed and the message stops.tops.
  941. Handlers in backgrounds
  942. Spark
  943. height
  944. height
  945. bkgnd script
  946. to handle buttonDown
  947.     beep 10
  948. to handle myMessage
  949.     go to page "Test"
  950. arrow
  951. -- Animate the message demo 
  952. showMe
  953. moveLSpark "et1"
  954. "bkgnd 
  955. showMe
  956. showMe
  957. moveLSpark
  958. moveLSpark
  959. moveLSpark
  960. bkgnd script
  961. bkgnd script
  962. bkgnd script
  963.     The special variable It is used
  964.     as a default container in 
  965.     OpenScript. Whenever you 
  966.     use a get command, 
  967.     OpenScript places the 
  968.     result in the variable It.
  969.     Ask and request commands 
  970.     also store their results in It.
  971.     For this exercise, each line in the "Commands" field is an OpenScript command that affects or uses the value of the variable It. The field's script executes each line as you click it at Reader level and shows the resulting value of It in the field labeled "Value of It:"
  972. 1.    Switch to Reader level and click each command. Observe how the command affects the value of It...t.f IT.alue of IT.e value of IT.........
  973. Stuff
  974. T'was brillig and the slithy toves did gyre and ...eeeeeeeeeeeeeeeeee
  975. Field Stuff
  976.  h    B!
  977. T'was brillig and the slithy toves did gyre and ...bal in the wabe
  978. to handle buttonUp
  979.     get the text of field "stuff"
  980.     if it contains "brillig" then
  981. end buttonUp
  982. ITCommands
  983. -- Execute a 
  984. "itValue" 
  985. place the resulting value 
  986. special 
  987. ^"It" 
  988. lineNum 
  989. buttonUp
  990. buttonUp
  991. itValue
  992. textFromPoint
  993. itValue
  994. lineNum
  995. get the text of field "Stuff"
  996. put it
  997. get (10 * 15)
  998. request it with "OK" or "Cancel"
  999. request it with "Yes" or "No"
  1000. itValue
  1001. Value of It:
  1002. Commands:
  1003. T'was brillig and the slithy toves did gyre and ...
  1004. sectionNumber
  1005. Forwarding a message
  1006. sectionNumber
  1007. If a handler contains a forward statement, the message is passed on to the next object in the hierarchy.y
  1008. Forwarding a message
  1009. Spark
  1010. height
  1011. height
  1012. arrow
  1013. bkgnd script
  1014. to handle buttonDown
  1015.     beep 10
  1016.     forward
  1017. to handle myMessage
  1018.     go to page "Test"
  1019. forward
  1020. -- Animate the message demo 
  1021. showMe
  1022. moveLSpark "et1"
  1023. "bkgnd 
  1024. showMe
  1025. showMe
  1026. moveLSpark
  1027. moveLSpark
  1028. moveLSpark
  1029. bkgnd script
  1030. bkgnd script
  1031. forward
  1032. moveLSpark
  1033. moveLSpark
  1034. forward
  1035. bkgnd script
  1036. More on forward
  1037. -- Animate the message demo 
  1038. showMe
  1039. moveLSpark "et1"
  1040. "bkgnd 
  1041. showMe
  1042. showMe
  1043. moveLSpark
  1044. button script
  1045. button script
  1046. button forward
  1047. moveLSpark
  1048. moveLSpark
  1049. bkgnd script
  1050. background forward
  1051. moveLSpark
  1052. book script
  1053. book script
  1054. book script
  1055. background forward
  1056. bkgnd script
  1057. bkgnd script
  1058. button forward
  1059. button script
  1060. sectionNumber
  1061. Objects further up in the hierarchy will handle a forwarded message if the objects have a handler for the message..
  1062. More on forward.
  1063. Spark
  1064. height
  1065. height
  1066. bkgnd script
  1067. to handle buttonDown
  1068.     forward
  1069.     beep 10
  1070. to handle myMessage
  1071.     go to page "Test"
  1072. background forward
  1073. book script
  1074. to handle buttonDown
  1075.     beep 30
  1076. the target to true
  1077.     set invert of the target to false
  1078. to handle myMessage
  1079.     go to page "Test"
  1080. button script
  1081. to handle buttonDown
  1082.     beep 10
  1083.     forward
  1084. endddd myMessage
  1085.     go to page "Test"
  1086. end"Test"
  1087. button forward
  1088. arrow
  1089. Background objects
  1090. sectionNumber
  1091. If you click an object located on the background, the object gets the message first. If the object doesn't have a handler for the message, the message passes to the background and so on.so on.
  1092. Background objectskground
  1093. Spark
  1094. height
  1095. height
  1096. arrow
  1097. -- Animate the message demo 
  1098. showMe
  1099. moveLSpark "bt1"
  1100. showMe
  1101. showMe
  1102. moveLSpark
  1103. moveLSpark
  1104. moveLSpark
  1105. moveLSpark
  1106. Clicking a page
  1107. sectionNumber
  1108. If you click the page, but away from any object, the message goes directly to the page.oes directly to the page.
  1109. Clicking a pageege
  1110. Spark
  1111. height
  1112. height
  1113. arrow
  1114. -- Animate the message demo 
  1115. showMe
  1116. moveLSpark "pgt"
  1117. "et5"
  1118. showMe
  1119. showMe
  1120. moveLSpark
  1121. moveLSpark
  1122. moveLSpark
  1123. moveLSpark
  1124. Objects in groups
  1125. -- Animate the message demo 
  1126. showMe
  1127. moveLSpark "et1"
  1128. showMe
  1129. showMe
  1130. moveLSpark
  1131. moveLSpark
  1132. moveLSpark
  1133. moveLSpark
  1134. moveLSpark
  1135. moveLSpark
  1136. sectionNumber
  1137. If you click an object in a group, the message goes first to the object, then to the group, then to the parent of the group (in this example, the page), and so on until the message is handled or until it reaches the ToolBook system.
  1138. Objects in groupss
  1139. Spark
  1140. height
  1141. height
  1142. arrow
  1143. The UniqueName
  1144. Basic concepts
  1145. hical Naviga
  1146. Objects in Groups
  1147. The object hierarchy
  1148. User-defined functions continue
  1149. Listing objects using push and p
  1150. sectionNumber
  1151.     The objective in this exercise is to write a handler to display the names or IDs of all the objects on a page, even if they are nested in groups. One technique is to use the push and pop commands. The basic steps for listing objects on the page are as follows:
  1152. A.    Get the value of the objects property for the page (a list of objects).
  1153. B.    Pop an item from the list:
  1154.         If the item identifies an object, not a group 
  1155.             display that object's name or ID
  1156.         otherwise, if the item identifies a group
  1157.             get the objects of the group
  1158.             push the objects onto the list of objects
  1159. C.     Repeat step B until the list is empty.
  1160.     Continued on the next page.ge. page. page.
  1161. Listing objects using push and pop
  1162. "Sample1"
  1163. Button Indic
  1164. group indic
  1165. Group
  1166. "2    6#
  1167. group indic
  1168. Group
  1169. The objects property of page "sample1" is the list of objects whose parent is the page. page.round.
  1170. Chapter Head
  1171. Click the right arrow to continue.rrrrrrrrr
  1172. Title
  1173. Table of Contents
  1174. -- Go 
  1175. the Table 
  1176. Contents 
  1177. buttonUp
  1178. buttonUp
  1179. Table of Contents
  1180. Table of Contents
  1181. -- If 
  1182. moved 
  1183. reposition 
  1184. on the 
  1185. -- user-defined property, home, 
  1186. /graphic covering 
  1187. -- When 
  1188. qmouse 
  1189. pressed, 
  1190. released, 
  1191. w. Finally, 
  1192. -- Move 
  1193. -- depending on 
  1194. parameter, x, which can be 
  1195. H15,15
  1196. buttonDown
  1197. moved
  1198. buttonUp
  1199. press
  1200. moved
  1201. buttonDown
  1202. press
  1203. buttonUp
  1204. press
  1205. previous
  1206. press
  1207. 7755,5480
  1208.      
  1209. Right
  1210. -- If 
  1211. moved, 
  1212. a user-defined property, home, 
  1213. -- the 
  1214. graphic covering 
  1215. -- When 
  1216. Bmouse 
  1217. pressed, 
  1218. released, 
  1219. w. Finally, 
  1220. -- Move 
  1221. -- depending on 
  1222. parameter, x, which can be 
  1223. H15,15
  1224. buttonDown
  1225. moved
  1226. buttonUp
  1227. press
  1228. moved
  1229. buttonDown
  1230. press
  1231. buttonUp
  1232. press
  1233. press
  1234. 8370,5475
  1235.      
  1236. Object types
  1237. -- Place the type 
  1238. {clicked 
  1239. "Type" 
  1240. Glocation
  1241. objectFromPoint(
  1242. "Object 
  1243. buttonup
  1244. buttonup
  1245. Object Type
  1246. Object Type
  1247. location
  1248. sectionNumber
  1249.     This page contains a script that will display the object type of an object you click.
  1250. 1.    Switch to Reader level.
  1251.     Use F3 or the Reader command from the Edit menu. If you're not at Reader level the script cannot function.
  1252. 2.    Click different objects on the page and observe the type displayed in the 
  1253.     field at the bottom of the page.
  1254.     Note: this exercise only shows information about objects on the page. It will not show information about background objects.
  1255. 3.    Switch back to Author level and create an object of your own. Switch to Reader level and click your new object.
  1256.     Was the result what you expected?he result what you expected?
  1257. Object types
  1258. Object Type
  1259. Object Type
  1260. User-Defined Messages
  1261. Typing multiple commands in the
  1262. An Object's Location
  1263. Building Expressions
  1264. More on forward
  1265. Typing multiple commands in the 
  1266. A user-defined function for sort
  1267. Elements of OpenScript
  1268. Handler placement
  1269. sectionNumber
  1270. startSection
  1271. Handler placement
  1272. Remember, if an object doesn't have a handler for a message, the message continues up the object hierarchy. You can often simplify an application by placing a single handler further up in the hierarchy that handles messages for similar objects. Such a handler can use the target system property to identify the object that first received the message.
  1273. The following exercise shows how placing a handler further up in the hierarchy can reduce the number of handlers needed.eded.
  1274. User-defined functions
  1275. startSection
  1276. sectionNumber
  1277. OpenScript has numerous built-in functions for calculating arithmetic, statistical, string, and other results. You can create your own functions by writing a special type of handler, called a "to get" handler.
  1278. Unlike a message handler, which runs in response to a message, a to
  1279. get handler runs only when its name is used in an OpenScript command.
  1280. mmand.
  1281. to area(self)
  1282. Area is a function that returns a the areArea is a function that returns a the arerens a the aren that returns a the are
  1283. User-defined functions
  1284. A self-correcting object
  1285. sectionNumber
  1286.     This exercise uses the Command window and shows how you can create a user-defined property to store an object's size.
  1287. 1.    Activate the Command window. Create a property called "originalSize" and set it to the bounds of the triangle by typing:
  1288.     set originalSize of polygon "triangle" to bounds 
  1289.         of polygon "triangle"
  1290. 2.    Select and resize the triangle, then type:
  1291.     set bounds of polygon "triangle" to originalSize 
  1292.         of polygon "triangle"
  1293. 3.    Display the value of the originalSize property in the Command window.
  1294.     Type: originalSize of polygon "triangle"""n "triangle"angle"then type:
  1295.         set bounds of polygon "triangle" to 
  1296.         originalSize of polygon "triangle"
  1297. A self-correcting objectc
  1298. triangle
  1299. Object names
  1300. -- Place the 
  1301. p, type 
  1302. {clicked
  1303. fields on 
  1304. . If 
  1305. 2mouse 
  1306. % but 
  1307. 1will be cleared.
  1308. Glocation
  1309. objectFromPoint(
  1310. "Object Name" 
  1311. Type" 
  1312. 0UniqueName" 
  1313. buttonup
  1314. buttonup
  1315. Object Name
  1316. Object Type
  1317. Object UniqueName
  1318. Object Name
  1319. Object Type
  1320. Object UniqueName
  1321. location
  1322. sectionNumber
  1323.     This page contains a script that will put the name, type, and uniqueName of any object you click into the fields at the bottom of the page.
  1324. 1.    Switch to Reader level.
  1325.     Use F3 or the Reader command from the Edit menu. The script cannot function at Author level.
  1326. 2.    Click each object on the page and observe the name, type, and uniqueName displayed.
  1327.     Note: this exercise will only show information about objects on the page. It will not show information about background objects.
  1328. 3.    Switch to Author level and create an object of your own. Return to Reader level and click your new object.
  1329.     Was the result what you expected??????????????
  1330. Object names
  1331. Object Name
  1332. Nameeeeeeee
  1333. Object Type
  1334. Object UniqueName
  1335. Unique Name
  1336. Red Square
  1337. Diamond
  1338. Pie Slice
  1339. Button
  1340. Hi There!
  1341. A user-defined function for chec
  1342. sectionNumber
  1343.     In this exercise, you will write a handler that defines a function that checks a character to see if it is a numeral.
  1344. 1.    Edit the script of this page and create a to get handler for a function called isNumber. The function should check a character supplied as a parameter and return true if the character is a numeral (0-9), or false if the character is not a numeral.
  1345.     This function is similar to the isAlpha function. For a hint click the "Hint" button.
  1346. 2.    Test the isNumber function by typing the following in the Command window:
  1347.     isNumber("3")
  1348.     isNumber("a")
  1349.     isNumber("a")
  1350.     isNumber("a")
  1351. A user-defined function for checking character type
  1352. to get isNumber testChar
  1353.         return testChar is in "0123456789"
  1354. -- Show 
  1355. the hint.
  1356. "Hint"
  1357. buttonUp
  1358. buttonUp
  1359. Local versus system variables
  1360. -- When leaving 
  1361. [the "totalSys" 
  1362. "totalLocal" 
  1363. -- fields.
  1364. 4count
  1365. leavePage
  1366. leavePage
  1367. totalLocal
  1368. totalSys
  1369. count
  1370. sectionNumber
  1371.     OpenScript has two types of variables: system and local. System variables retain their value when a handler has finished and can be shared between handlers. Local variables are discarded.
  1372.     In this example the two buttons, "System" and "Local", contain the scripts displayed below them. The scripts are identical except for the system declaration in one compared to the local declaration in the other.
  1373.     Each time one of the buttons is clicked, the value in the variable count is incremented and displayed in the total field.
  1374. 1.    Switch to Reader level and try clicking the buttons. How do they act differently??y???? do they act differently??????
  1375. Local versus system variables
  1376. to handle buttonUp
  1377.     system count
  1378.     if count is null then
  1379.         set count to 0
  1380.     increment count
  1381.     set the text of field "totalSys" to count
  1382. System
  1383. -- Increment the 
  1384. ^"count" 
  1385. display 
  1386. result
  1387. %"totalSys" 
  1388. . The 
  1389. ^, so its value remains 
  1390. ghandler 
  1391. finished 
  1392. -- running.
  1393. buttonUp
  1394. buttonUp
  1395. totalSys
  1396. count
  1397. System
  1398. totalSys
  1399. System Variable:
  1400. to handle buttonUp
  1401.     local count
  1402.     if count is null then
  1403.         set count to 0
  1404.     increment count
  1405.     set the text of field "totalLocal" to count
  1406. Local
  1407. -- Increment the 
  1408. ^"count" 
  1409. display 
  1410. result
  1411. %"totalLocal" 
  1412. . The 
  1413. ^, so its value 
  1414. discarded 
  1415. Fhandler 
  1416. -- finished running.
  1417. buttonUp
  1418. buttonUp
  1419. totalLocal
  1420. count
  1421. Local
  1422. totalLocal
  1423. Local Variable::
  1424. Setting an object's size with a 
  1425. sectionNumber
  1426.     An object's bounds property is a built-in property that contains coordinates of the upper left and lower right corners of the object's bounding rectangle. The size of the object (width and height) can be calculated by subtracting the left coordinate from the right and the top from the bottom. The size of an object can be set by adding the width and height to the left and top coordinates. 
  1427.     In this exercise you'll write a to set handler to set the size of an ellipse. After adding the handler to the object's script you should be able to type "set the objectSize of ellipse green to 800,300" in the Command window to change the object's size and have its bounds change accordingly.
  1428.     Continued on the next page.
  1429. ext page.
  1430. 1.    Read about to get and to set handlers in the Using OpenScript manual.
  1431. 2.    Following the guidelines above write handlers
  1432. Setting an object's size with a to set handler
  1433. Verifying data during input with
  1434. sectionNumber
  1435.     In this example you will write a keyChar handler to allow only numerals to be typed in the Number field shown to the right.
  1436. 1.    Look up the keyChar message in OpenScript help.
  1437. 2.    Try to write a keyChar handler in the script of the "Number" field to the right that allows only numerals to be typed.
  1438.     Hint: If a character from 0 to 9 is typed, the message should be forwarded. Otherwise, the handler should beep and do nothing. Test the handler by switching to Reader level then typing in the field.
  1439.     To see one solution, switch to Reader level and click the "Hint" button.....el and click the "Hint" button.
  1440. Verifying data during input with a keyChar handler
  1441. to handle keyChar key
  1442.     get ansiToChar(key)
  1443.     if it is in "0123456789" then
  1444.         forward
  1445.     else
  1446.         beep 5
  1447.     end if
  1448. end end if
  1449. -- Show 
  1450. the hint.
  1451. "Hint"
  1452. buttonUp
  1453. buttonUp
  1454. Number:
  1455. Branching with conditions
  1456.     The conditions/when/else control structure  allows you to accomodate many conditions in one structure.
  1457. 1.    Create a button.
  1458. 2.    Edit the button's script to use the request command to request a color: Light, Medium or Dark. Then, using the conditions control structure, set the button's fillColor to "White", "Cyan", or "Red" according to the chosen value.
  1459.     For one solution, switch to Reader level and click the "Hint" button.
  1460. 3.    Test your button by clicking it at Reader level.
  1461. Branching with conditions
  1462. to handle buttonUp
  1463.     request "Which color?" with "Light" or \
  1464.         "Medium" or "Dark"
  1465.     conditions
  1466.         when it is "Light"
  1467.             set my fillColor to White
  1468.         when it is "Medium"
  1469.             set my fillColor to Cyan
  1470.         when it is "Dark"
  1471.             set my fillColor to Red
  1472. enddddd
  1473. -- Show 
  1474. the hint.
  1475. "Hint"
  1476. buttonUp
  1477. buttonUp
  1478. sectionNumber
  1479. Changing an object's bounds
  1480. sectionNumber
  1481.     Another of an object's properties is its bounds. The bounds of an object is a list of four numbers representing the coordinates (x,y) of the upper left corner and lower right corner of a rectangle bounding the object. In this exercise you'll write a handler to change the bounds of the smiley face, which is a group.
  1482. 1.    Look at the script of the "Flat Face" button. Also look at the script of the "Round Face" button.
  1483.     Select the button and use the Button Properties command or hold down the Ctrl key and double-click the button with the selection arrow. Notice the command that changes the bounds of the "Smiley" group.
  1484. 2.    Switch to Reader level and click each of the buttons.
  1485. ttons.
  1486. button to try it out.
  1487. Changing an object's bounds
  1488. Smiley
  1489. Round Face
  1490. Flat Face
  1491. -- Return the 
  1492. "Smiley" 
  1493. its original 
  1494. 5776, 837, 7998, 3162
  1495. buttonUp
  1496. buttonUp
  1497. Smiley
  1498. -- Change the 
  1499. "Smiley" 
  1500. looks flat
  1501. 5776, 837, 7998, 1500
  1502. buttonUp
  1503. buttonUp
  1504. Smiley
  1505. Restoring menus
  1506.     Adding or deleting menus and menu items from the menu bar changes the menu until you change it back--even if you open another book. You can restore the menu bar to the ToolBook default by using the restore menubar command.
  1507. 1.    Type the following command in the Command window:
  1508.     restore menubar at both
  1509.     You can ensure that your menu bar is restored whenever you open a new book by adding a leaveBook handler to the script of any book that changes the menu. See the handler on the right for an example.
  1510. xamples.
  1511. Restoring menus
  1512. -- leaveBook handler to restore the menu
  1513. -- bar when going to another book.
  1514. to handle leaveBook
  1515.         restore menuBar at both
  1516. -- leavePage handler to restore the menu
  1517. -- bar when going to another page.
  1518. to handle leavePage
  1519.         restore menuBar at both
  1520. sectionNumber
  1521. Topic
  1522. Branching with If/then/else
  1523. sectionNumber
  1524.     The if/then/else control structure allows you to test a condition and do different things as a result. In this exercise you will use if/then/else to test the results of an ask command.
  1525. 1.    Edit the "Set Attendance" button's script and create a buttonUp handler. In the handler, ask for the attendance. Check the result to see if it is between 0 and 10. If it isn't, beep. If it is, set the text of field "Attendance" to the value.
  1526.     To see one solution, switch to Reader level and click the "Hint" button (click again to make the hint disappear).
  1527. 2.    Try the script by clicking the "Set Attendance" button...on.ld's scripts and switch to Reader level. el.     l. 
  1528. Branching with If/then/else
  1529. Attendance
  1530. Attendance
  1531. to handle buttonUp
  1532.     ask "Attendance?"
  1533.     if it >=0 and it <= 10 then
  1534.         set text of field "Attendance" to it
  1535.     else
  1536.         beep 20
  1537.     end if
  1538. endddddd
  1539. Set Attendance
  1540. -- Show 
  1541. the hint.
  1542. "Hint"
  1543. buttonUp
  1544. buttonUp
  1545. Containers
  1546. Changing an Object's Bounds
  1547. The hierarchy 2
  1548. Drawing Objects from a Script
  1549. To set handler continued
  1550. Listing objects continued
  1551. and P
  1552. sectionNumber
  1553.     In this exercise you will write a handler that displays the name or ID of all the objects on a page. To prepare, look at OpenScript Help for information on the objects and object properties.
  1554. 1.    Create a button and write a handler for it that will display the names or IDs of objects on the page in the "Object List" field to the right.
  1555.     To see one solution, switch to Reader level and click the "Hint" button. You can cut and paste this handler into the field's script and then experiment by making modifications. The handler can be modified in numerous ways such as displaying information about object properties for each object or indenting objects in groups.ps..ng objects in groups.. groups.
  1556. Listing objects, continued
  1557. blank hint
  1558. to handle buttonUp
  1559.     clear text of field "Object List"
  1560.     set x to objects of this page
  1561.     while x is not null
  1562.         pop x
  1563.         put object of it && quote&name of it"e\
  1564.             & CRLF after text of field "Object List"
  1565.         -- For a group, push its objects back onto
  1566.         -- the list of objects to display
  1567.         if object of it is "group"
  1568.             push objects of it onto x
  1569.         end
  1570. end buttonUp
  1571. Object List
  1572. -- Show 
  1573. the hint.
  1574. "Hint"
  1575. buttonUp
  1576. buttonUp
  1577. Geometrics
  1578. Square
  1579. Triangle
  1580. Object List:
  1581. (    used
  1582.     true
  1583. Objects
  1584. sectionNumber
  1585. startSection
  1586. Objectssssssssss
  1587. A ToolBook book consists of objects such as buttons, fields, graphics, and pages. An author defines the objects, their properties, and their behavior. The book's reader interacts with the objects.
  1588. As an example, this page contains record fields (for text), several buttons, and various graphic objects.page also contains a foreground that could contain objects unique to this page.e to this page.
  1589. Objects
  1590. Handlers in Objects
  1591. Visual Effects
  1592. Properties
  1593. sectionNumber
  1594. startSection
  1595. Properties
  1596. Objects have properties. You can change an object's appearance or select different built-in ToolBook behaviors by changing the object's properties. You can add to or replace an object's built-in behavior by changing the object's script.
  1597. The following exercises show some examples of changing properties.
  1598. Properties
  1599. continue
  1600. A final note ...
  1601. Using the Ask Command
  1602. A Self-Correcting Object
  1603. Typing multiple commands in the 
  1604. sectionNumber
  1605.     You can type multiple commands in the Command window at the same time by separating them with semicolons.
  1606. 1.    Type the following commands in the Command window and press Enter when you're finished:
  1607.     step i from 1 to 100; move ellipse dot by 10,10;  end
  1608. 2.    What commands would you type to move the dot back to its starting point?
  1609. 3.    What commands would you type to move the dot back to its starting point?
  1610. Typing multiple commands in the Command window
  1611. Mouse movement and button messag
  1612. -- When leaving 
  1613. [the "Messages" 
  1614. leavePage
  1615. leavePage
  1616. Messages
  1617. sectionNumber
  1618.     Numerous messages are sent to an object as a result of mouse movement and actions. The messages are:
  1619.     mouseEnter            mouseLeave
  1620.     buttonDown               buttonUp
  1621.     buttonStillDown           rightButtonDown
  1622.     buttonDoubleClick        rightButtonUp
  1623.     rightButtonDoubleClick
  1624. 1.    Switch to Reader level
  1625.     Press F3. (mouse messages aren't sent at Author level).
  1626. 2.    As you move the mouse over the magenta rectangle and click, the messages sent to the rectangle will be displayed in the "Messages" field. Try to display each of the ones listed above..........
  1627. Mouse movement and button messagess
  1628. Messages
  1629. Messages:
  1630. Object drawing and display
  1631. Object drawing and display
  1632. OpenScript has commands to draw objects as well as to manipulate them in various ways. The following exercises use OpenScript commands to draw, show, hide, and move objects.nScript commands.ds.ving objects.
  1633. startSection
  1634. sectionNumber
  1635. Navigation and visual effects
  1636. sectionNumber
  1637. startSection
  1638. Navigation and visual effects
  1639. OpenScript has commands that you can use to navigate between pages and books. It also has commands that you can use to create different visual effects when switching pages. 
  1640. The following exercise looks at page navigation as well as the three special effects ToolBook provides.
  1641. Types of Objects
  1642. Branching with Conditions
  1643. Setting an Object's Size with a 
  1644. User-defined functions
  1645. FxZoom fxDissolve and fxWipe
  1646. A self-sorting field
  1647. sectionNumber
  1648. startSection
  1649. A self-sorting field
  1650. One of the powerful things about ToolBook's object-oriented approach is that you can design objects, complete with scripts, that can be cut and pasted into other applications. An example of this is a field that has a script to sort itself. Such a field could be pasted into other applications ready to go.
  1651. The following exercise shows how to create a self-sorting field.d.orting field.
  1652. A simple object browser
  1653. When a page or background has many objects, it can be difficult to keep track of what their names are, which ones have scripts and so on. One tool that can make it easy to inspect objects and their properties is a script that displays information on objects you click.
  1654. In the following exercise you will write a script that allows you to quickly see information about objects.jects..cts..bjects...cts.
  1655. startSection
  1656. sectionNumber
  1657. A simple object browser
  1658. Structure of a Handler
  1659. Another Example of the step cont
  1660. User-defined functions 1
  1661. Listing all objects on a page
  1662. sectionNumber
  1663. startSection
  1664. Listing all objects on a page
  1665. Backgrounds, pages, and groups all have an objects property. Its value is a list of all the objects of the background, page or group. Listing objects from the objects property is simple unless one of the objects is a group. This is because a group contains other objects. 
  1666. The following exercise shows an example of using the push and pop commands to list objects even if they are within groups.following exercise shows how to write a handler that lists the object type and name of objects on a page.............s on a page.page.n a page.......
  1667.  Contents
  1668. Showing all Objects on a Page
  1669. Table of Contents
  1670. Using the ask command
  1671. sectionNumber
  1672. 1.    Create a button and label it "Get First Name".
  1673.     Use the button tool from the tool palette.
  1674. 2.    Edit the button's script and type:
  1675.     to handle buttonUp
  1676.         ask "Type your first name" with "Sigmund"
  1677.         set the text of field "First Name" to it
  1678.     end buttonUp
  1679. 3.    Switch to Reader level and click the button.
  1680.     What happens when you click the Cancel button? What happens if you remove "with "Sigmund"" from the Ask command in the script??pt? if you remove the "with "Sigmund"" from the Ask command?
  1681. Using the ask commanddddd
  1682. First Name
  1683. First Namest Name
  1684. Structure of a handler
  1685. Structure of a handler
  1686. A handler has a beginning, middle, and end.
  1687. In the following exercise you will write a simple handler for a buttonUp message.ritten using OpenScript. The end is a line identifying the end of the handler.
  1688. In the following exercise you will 
  1689. write a simple buttonUp handler.you will write a simple buttonUp handler.
  1690. sectionNumber
  1691. -- Changes to reader level when
  1692. -- page is entered.
  1693. to handle enterPage
  1694.     send Reader
  1695. end enterPagerPageeeeee
  1696. Beginning: identifies the name of the message to which this handler responds.
  1697. Middle: contains instructions in OpenScript saying what to do when the message is received.
  1698. End: marks the end of the handler
  1699. ToolBook Programming
  1700. Name versus ID
  1701. Setting and Getting Field Text i
  1702. Handlers in Pages
  1703. A simple object browser using ri
  1704. Table of Contents
  1705. Chapters
  1706. Sections
  1707. -- Turn the 
  1708. selected section 
  1709. clicked.
  1710. turnToSection
  1711. pressed.
  1712.         -- 
  1713. pkey 
  1714. default processing
  1715. -- Algorithm:
  1716. -- Get 
  1717. currently 
  1718. . If 
  1719. named 
  1720. strip(
  1721. oselectedTextLines 
  1722. Click
  1723. buttonDoubleClick
  1724. keyChar
  1725. turnToSection
  1726. buttonDoubleClick
  1727. qturnToSection
  1728. keyChar
  1729. qturnToSection
  1730. turnToSection
  1731. strip
  1732. -- Display 
  1733. the help 
  1734. helpObject 
  1735. buttonUp
  1736. buttonUp
  1737. helpObject
  1738. Close the Workbook
  1739. -- Go 
  1740. same 
  1741. buttonUp
  1742. buttonUp
  1743. Close the Workbook
  1744. Title
  1745. -- Hide 
  1746. help 
  1747. clicked.
  1748. default
  1749. buttonDoubleClick
  1750. buttonDoubleClick
  1751. default
  1752. Click a chapter name on the left to see  that chapter's sections on the right.
  1753. Double-click a section name on the right to go to that section. As you complete each section or chapter, it will be marked with an asterisk beside its name.
  1754. Double-click this text to make it disappear
  1755. Chapter Name
  1756. Using the workbook
  1757. Using the workbook
  1758. startSection
  1759. sectionNumber
  1760. Exercise pages
  1761. Exercise pages
  1762. On exercise pages, ToolBook
  1763. automatically changes to Author
  1764. level so you must use 
  1765. <Ctrl>+arrow keys or commands 
  1766. from the Page menu to turn pages.
  1767. To complete an exercise, follow directions in the field on the left and use the space to the right as your work area.area..............
  1768. Instructions
  1769. Title
  1770. Exercise Page
  1771. startSection
  1772. sectionNumber
  1773. Table of Contents
  1774. Sections6
  1775.     A self-sorting field
  1776.     Listing all objects on a page
  1777.     A simple object Browser
  1778. Sections5
  1779.     User-defined properties
  1780.     User-defined messages
  1781.     Handler placement
  1782.     User-defined functions
  1783.     Handling keystrokes
  1784.     To get and to set handlers
  1785. Sections4
  1786.     The Command window
  1787.     Ask and request
  1788.     Control structures
  1789.     Object drawing and display
  1790.     Navigation and visual effects
  1791.     Push and pop
  1792.     Menus
  1793. Sections3
  1794.     Object identifiers
  1795.     Properties
  1796.     Containers
  1797.     Lists
  1798.     Expressions
  1799. Sections2
  1800.     Toolbook programming
  1801.     Objects
  1802.     Messages
  1803.     Handlers
  1804.     The object hierarchy
  1805. Sections1
  1806.     What this book contains
  1807.     Navigating in this book
  1808.     Exercise pages
  1809.     OpenScript Help
  1810.     A final note ...
  1811.     What this book contains
  1812.     Navigating in this book
  1813.     Exercise pages
  1814.     OpenScript Help
  1815.     A final note ... keystrokes
  1816.     To get and to set handlersers
  1817. Using the workbooktionsic concepts    Elements of OpenScript    OpenScript commands    Advanced topics    OpenScript applicatio
  1818. OpenScript Workbook
  1819.     Using the workbook
  1820.     Basic concepts
  1821.     Elements of OpenScript
  1822.     OpenScript commands
  1823.     Advanced topics
  1824.     OpenScript applicationssonsOpenScript applicationsions
  1825. OpenScript Help
  1826. e Help
  1827. OpenScript Helpne Help
  1828. ToolBook comes with an extensive online OpenScript encyclopedia called OpenScript Help. To read OpenScript Help, activate the Command window by clicking it or open a Script window, then press <F1>.
  1829. OpenScript Help works the same way as standard Windows Help so it is similar to online help in other Windows applications. following exercise you getript Help....
  1830. ing [
  1831. startSection
  1832. sectionNumber
  1833. A final note ...
  1834. A final note ...
  1835. The exercises in this book are just starting points. Feel free to pick and choose topics that seem interesting, explore on your own, and make up your own examples.
  1836. Now, click the forward arrow to begin learning about OpenScript or click the Table of Contents button to turn to the table of contents.
  1837. ny o%
  1838. startSection
  1839. sectionNumber
  1840. Developing ToolBook Applications
  1841. OpenScript applications
  1842. User-defined functions 2
  1843. The object hierarchy
  1844. sectionNumber
  1845. startSection
  1846. The object hierarchyy
  1847. When a message is sent to an
  1848. object, it travels up what's called
  1849. the object hierarchy until
  1850. the message locates 
  1851. a handler for itself or 
  1852. until the message
  1853. reaches the ToolBook 
  1854. system.
  1855. Object
  1856. Button Indic
  1857. ToolBook
  1858. System
  1859. stemstem
  1860. Background
  1861. Page 
  1862. Object
  1863. Button Indic
  1864. group indic
  1865. Group
  1866. "2    6#
  1867. group indic
  1868. Group
  1869. Object
  1870. Button Indic
  1871. group indic
  1872. Group
  1873. Message
  1874. Spark
  1875. l+height
  1876. Spark
  1877. ,height
  1878. Spark
  1879. .height
  1880. Spark
  1881. h/height
  1882. Spark
  1883. 0height
  1884. Spark
  1885. 2height
  1886. 3used
  1887. 3true
  1888. Using OpenScript Help
  1889. Welcome
  1890. Exercise Pages
  1891. Specifying Parts of Strings
  1892. Developing ToolBook applications
  1893. Developing ToolBook applications
  1894. Developing a ToolBook application usually begins with the user interface. You can lay out the buttons, fields and other objects, then develop scripts to make them behave the way you want. While traditional program development tends to be linear, ToolBook development is more flexible and modifications can be made and tested readily.
  1895. to kE
  1896. sectionNumber
  1897. Handlers
  1898. Handler Placement
  1899. Object Names
  1900. Navigation and Visual Effects
  1901. Using the Request Command
  1902. ion, cont.
  1903. The Command Window
  1904. ctures - Looping
  1905. fx destination
  1906. A buttonUp handler Higher in the
  1907. Containers
  1908. Containers
  1909. A container is anything in OpenScript that can hold a value. Containers can be properties, variables, the special variables It and sysError, or the Command window.
  1910. The following exercises demonstrate using local variables versus system variables and the special variable It. Properties are covered in another section..c.topic.
  1911. objeE
  1912. startSection
  1913. sectionNumber
  1914. Handling standard menu choices
  1915. sectionNumber
  1916.     In this exercise you will see a script that alters how ToolBook responds to the Author menu item. When you choose a menu item, ToolBook sends a message to the current page. The message name is the same as the menu item, but without spaces or special characters.
  1917. 1.    Switch to Reader level and choose Author from the Edit menu.
  1918.     Notice what happens.
  1919. 2.    Edit the script of this page and add the handler displayed to the right.
  1920.     Choose Page Properties from the Object menu.
  1921. 3.    Change to Reader level again and choose Author from the Edit menu.
  1922.     What's different this time?
  1923. Handling standard menu choices
  1924. script1
  1925. to handle author
  1926.         request "Switch to Author level?" \
  1927.             with "Yes" or "No"
  1928.       if it is "Yes"
  1929.             forward
  1930.       end if
  1931. end author
  1932. end author
  1933. e enterBook
  1934. --positions the workbook window
  1935.     set syslevel to author
  1936.     send sizeToPage
  1937. end enterBook
  1938. Author Handler
  1939. A popup definition using show an
  1940. sectionNumber
  1941.     In this exercise you will write scripts to hide and show a field that contains a hotword definition.
  1942. 1.    Double-click in the green field to begin editing its text. Select the bold word "score" in the text and make it a hotword.
  1943.     Choose the Create Hotword command from the Text menu or press Ctrl-W. To outline the hotword choose Show Hotwords from the Text menu.
  1944. 2.    Edit the script of the hotword and create a buttonUp handler that shows the field called "definition" (the white field).
  1945. 3.    Edit the script of field "definition" to hide itself when it is clicked (you can use the special term self in the hide command).
  1946. 4.    Switch to Reader level and try your scripts by clicking the fields. 
  1947. A popup definition using show and hidend Hideddddddddd
  1948. hotwords
  1949. Four score and seven years ago, our fathers brought forth a new nation, conceived in liberty and dedicated to the proposition that all men are created equal.
  1950. Definition
  1951. A score is twenty years. "Four score and seven" is eighty-seven years."ight-seven years."
  1952. -- Handler for the hotword
  1953. to handle buttonUp
  1954.       show field "definition"
  1955. end buttonUp
  1956. -- Handler for the popup definition
  1957. to handle buttonUp
  1958.       hide self
  1959. end buttonUp
  1960. -- Show 
  1961. the hint.
  1962. "Hint"
  1963. buttonUp
  1964. buttonUp
  1965. -- Add the message 
  1966. ppassed 
  1967. "msgText" parameter 
  1968. /"messages" 
  1969. . If its 
  1970. overflowing, 
  1971. A are added. Once 500 lines 
  1972. _ have accumulated, 
  1973. [them 
  1974. logMessage 
  1975. oldSuspend 
  1976.  & CRLF 
  1977. ) > 500 
  1978. -- Post 
  1979. names 
  1980. mouse 
  1981.  received 
  1982. buttonDown
  1983. mouseEnter
  1984. buttonStillDown
  1985. buttonUp
  1986. logMessage
  1987. buttonDoubleClick
  1988. rightButtonDown
  1989. mouseLeave
  1990. rightButtonUp
  1991. rightButtonDoubleClick
  1992. logMessage
  1993. messages
  1994. oldSuspend
  1995. msgText
  1996. mouseEnter
  1997. logMessage
  1998. mouseEnter
  1999. mouseLeave
  2000. logMessage
  2001. mouseLeave
  2002. buttonDown
  2003. logMessage
  2004. buttonDown
  2005. buttonStillDown
  2006. logMessage
  2007. buttonStillDown
  2008. buttonUp
  2009. logMessage
  2010. buttonUp
  2011. buttonDoubleClick
  2012. logMessage
  2013. buttonDoubleClick
  2014. rightButtonDown
  2015. logMessage
  2016. rightButtonDown
  2017. rightButtonUp
  2018. logMessage
  2019. rightButtonUp
  2020. rightButtonDoubleClick
  2021. logMessage
  2022. rightButtonDoubleClick
  2023. Working with objects from the Co
  2024. sectionNumber
  2025. 1.    Display the Command window.
  2026.     Press Shift+F3.
  2027. 2.    Type each of the following commands in the Command window. Press Enter after each command. 
  2028.     select ellipse "dot"
  2029.     unselect ellipse "dot"
  2030.     put position of ellipse "dot"
  2031.     move ellipse "dot" by 100,100
  2032.     set the fillColor of ellipse "dot" to green
  2033. set bounds of ellipse "dot" to 300,300,1300,1300
  2034.     edit the script of ellipse "dot"
  2035.     You can find out more about these commands in OpenScript Help.penScript manual.al.n the Using OpenScript manual. information on each command in the Using OpenScript manual."""""""""""""""""""""
  2036. Working with objects from the Command window
  2037. -- When the mouse 
  2038. pressed, 
  2039. released, 
  2040. buttonDown
  2041. buttonUp
  2042. buttonDown
  2043. 240,50,100
  2044. buttonUp
  2045. 60,50,100
  2046. Adding menus and menu items
  2047. sectionNumber
  2048.     The script to the right shows an example of adding a custom menu and menu items.
  2049. 1.    Edit the script of this page and type the handler displayed to the right.
  2050.     An easy way to do this is to type the following in the Command window:
  2051.     set script of this page to text of field "script1"
  2052. 2.    Install the menus by sending a setupMenu message to this page.
  2053.     Send the setupMenu message by typing the following in the Command window:
  2054.     send setupMenu
  2055. 3.    Try the new menu items.
  2056.     See the next exercise to restore the menu bar.
  2057.  Switch back to Author level.
  2058. Adding menus and menu items
  2059. script1
  2060. to handle setupMenu
  2061.     add menu"Script" at both
  2062.     add menuitem "Object" to menu "Script" at both
  2063.     add menuitem "Page" to menu "Script" at both
  2064.     add menuitem "Book" to menu "Script" at both
  2065.     deactivate menuitem "Object" at Reader
  2066. end setupMenu
  2067. to handle Object
  2068.     if the selection is not null
  2069.         edit the script of the selection
  2070.     end if
  2071. end Object
  2072. to handle Page
  2073.       edit the script of this page
  2074. end page
  2075. to handle book
  2076.       edit the script of this book
  2077. end book
  2078. to handle leavepage
  2079.       restore menubar at both
  2080. end leavepagee
  2081.       restore menubar at both
  2082. end leavepageeeeeeeeenubar at both
  2083. end leavepageepage leavepageepageleavepageepageepageepageepageepageeeeee
  2084. The uniqueName
  2085. sectionNumber
  2086. The uniqueName
  2087. An object's uniqueName identifies the object. It includes the object's ID, the page it is on and the name of the book it is in.
  2088. The following example shows you the name, object type, and uniqueName of several common objects.........ere the object is located.
  2089. The following example shows you the name, object type, and uniqueName of several common objects.
  2090. Forwarding a Message
  2091. age Hierarchy
  2092. Object Identifiers
  2093. The pattern property
  2094.     Another of an object's properties is its pattern property. This pattern is used to fill shapes.
  2095. 1.    Look up the pattern property using the Search button in OpenScript Help.
  2096.     Activate the Command window and press F1.
  2097. 2.    The button, "Watch", contains the script displayed at the bottom of this page. Examine the script and identify the line that sets the pattern property.
  2098. 3.    Switch to Reader level and click the "Watch" button.
  2099. 4.    Edit the button's script and add a line so that the pattern returns to solid after displaying the other patterns..erns.s.
  2100. The pattern propertyyyyyyyyyyyyyy of 
  2101. script1
  2102. -- Changes the pattern property of a rectangle
  2103. -- to all possible patterns.
  2104. to handle buttonUp
  2105.     step i from 1 to 128
  2106.         set pattern of rectangle "boob toob" to i
  2107. endddddddddddddd
  2108. Boob Toob
  2109. Watch
  2110. -- Change the 
  2111. property 
  2112. possible patterns.
  2113. "boob toob" 
  2114. buttonUp
  2115. buttonUp
  2116. boob toob
  2117. Watch
  2118. sectionNumber
  2119. Topic
  2120. ction
  2121. -- Switch 
  2122. Reader level 
  2123. entering 
  2124. enterBackground
  2125. enterBackground
  2126. Reader
  2127. Page Leader
  2128. Title
  2129. Table of Contents
  2130. -- Go 
  2131. the Table 
  2132. Contents 
  2133. buttonUp
  2134. buttonUp
  2135. Table of Contents
  2136. Table of Contents
  2137. -- If 
  2138. moved 
  2139. reposition 
  2140. on the 
  2141. -- user-defined property, home, 
  2142. /graphic covering 
  2143. -- When 
  2144. qmouse 
  2145. pressed, 
  2146. released, 
  2147. w. Finally, 
  2148. -- Move 
  2149. -- depending on 
  2150. parameter, x, which can be 
  2151. H15,15
  2152. buttonDown
  2153. moved
  2154. buttonUp
  2155. press
  2156. moved
  2157. buttonDown
  2158. press
  2159. buttonUp
  2160. press
  2161. previous
  2162. press
  2163. 7755,5480
  2164.      
  2165. Right
  2166. -- If 
  2167. moved, 
  2168. a user-defined property, home, 
  2169. -- the 
  2170. graphic covering 
  2171. -- When 
  2172. Bmouse 
  2173. pressed, 
  2174. released, 
  2175. w. Finally, 
  2176. -- Move 
  2177. -- depending on 
  2178. parameter, x, which can be 
  2179. H15,15
  2180. buttonDown
  2181. moved
  2182. buttonUp
  2183. press
  2184. moved
  2185. buttonDown
  2186. press
  2187. buttonUp
  2188. press
  2189. press
  2190. 8370,5475
  2191.      
  2192. Hiding and showing objects using
  2193. User-Defined Properties
  2194. Push and Pop
  2195. A popup definition using Show an
  2196. Handlers
  2197. sectionNumber
  2198. startSection
  2199. Handlerssandlerss
  2200. When an object receives a message, it can respond to the message or ignore it. If the object ignores the message, the message gets passed on to the group, page, background, or book that contains the object.
  2201. In order to respond to a message, an object must have a "handler" for that message in its script.
  2202. ript.
  2203. d is a line identifying the end of the handler. In the following exercise you will write a simple buttonUp handler.
  2204. Another example of the step cont
  2205. sectionNumber
  2206.     Here's another example of using the step control structure.
  2207. 1.    Edit the script of the "Clear Names" button.
  2208. 2.    Create a buttonUp handler to clear the names of the fields. The fields are called "Name1", "Name2", and so on, through "Name6".
  2209.     To see one solution, switch to Reader level and click the "Hint" button.
  2210. Another example of the step control structure
  2211. Name1
  2212. Name6
  2213. Name5
  2214. Frank
  2215. Name4
  2216. Name3
  2217. Henderson
  2218. Name2
  2219. Bertrand
  2220. Clear Names
  2221. to handle buttonUp
  2222.     step i from 1 to 6
  2223.         set fieldName to "Name" & i
  2224.         clear the text of field fieldName
  2225. endddd1 seconds
  2226. end    beep 10
  2227.     end if
  2228. -- Show 
  2229. the hint.
  2230. "Hint"
  2231. buttonUp
  2232. buttonUp
  2233. exercise
  2234. Introduction
  2235. Message Demo
  2236. Close the workbook
  2237. -- When entering the 
  2238. label on 
  2239. 8icon
  2240. /s_launchedFrom
  2241. ^. If 
  2242. Lworkbook 
  2243. -- Quick Tour, 
  2244. ewill be "
  2245. ." Otherwise, 
  2246. probably be 
  2247. "returnBook" 
  2248. enterPage
  2249. enterPage
  2250. returnBook
  2251. s_launchedFrom
  2252. Close the workbookk
  2253. After completing the exercises
  2254. in this workbook, you are
  2255. ready to begin writing
  2256. scripts and applications
  2257. on your own....
  2258. Double-click the book icon to close this workbook. If you opened the workbook from the Application Sampler, the Application Sampler will be opened............... to open another book called the OpenScript Work Book. When         you are finished 
  2259.         with the Work 
  2260.         Book the 
  2261.         Quick Tour will 
  2262.         resume.
  2263. returnBook
  2264. -- When 
  2265. }-clicked, 
  2266. -- label 
  2267. d(since 
  2268. -- become unshaded) 
  2269. message (which 
  2270. , be intercepted
  2271. handler 
  2272. a mouse 
  2273. pressed over 
  2274. Hchanging its 
  2275. -- Trap 
  2276. ignore 
  2277. }messages
  2278. Click
  2279. buttonDoubleClick
  2280. buttonDown
  2281. buttonUp
  2282. buttonDoubleClick
  2283. 0,100,0
  2284. buttonDown
  2285. 0,50,100
  2286. buttonUp
  2287. :PHYSSIZE
  2288. sectionNumber
  2289. What this Book Contains
  2290. Object Drawing and Display
  2291. Menus
  2292. Messages
  2293. Accessing Items in Lists
  2294. A simple object browser
  2295. User-defined functions, continue
  2296.  Cont.
  2297. OpenScript Online Help
  2298. Control Structures
  2299. Ask and Request
  2300. Types of objects
  2301. sectionNumber
  2302. Types of objects
  2303. ToolBook has several different types of objects:
  2304. Books                                Record fields
  2305. Backgrounds                        Hotwords
  2306. Pages                                Groups
  2307. Buttons                                Graphic objects (pictures, draw
  2308. Fields                                objects, and paint objects)
  2309.                         
  2310. Writing a simple buttonUp handle
  2311. sectionNumber
  2312. 1.    Create a rectangle on this page.
  2313.     Use the rectangle tool from the tool palette.
  2314. 2.    Edit the script of the rectangle.
  2315. Click the selection tool in the tool palette.
  2316.     Choose Graphic Properties from the Object menu and click the Script button.
  2317. 3.    Enter and save the following script (use the Exit/Update command in the Script menu):
  2318.     to handle buttonUp
  2319.             hide self
  2320.             pause 2 seconds
  2321.             show self
  2322.         end
  2323. 4.    Switch to Reader level and click the rectangle.    
  2324.     What messages did clicking the rectangle send? Which message caused the rectangle to disappear? What about the other message????????????????????????????????????????????????????????????????
  2325. Writing a simple buttonUp handler
  2326. Please note:  Read the instructions on this page carefully before executing them. 
  2327. Other windows will appear in front of this window. If you need to move these windows to read the instructions, drag their title bar.
  2328. Object identifiers
  2329. sectionNumber
  2330. startSection
  2331. Object identifiers
  2332. In writing scripts you often have to refer to an object, perhaps to hide or show it, or to change it in some way. To refer to an object you use a combination of the object's type (e.g. field, button) and the object's name or ID. If the object isn't on the current page you may also have to add location information. As an example, to refer to the blue ellipse 
  2333. on this page you could use ellipse "oval" or 
  2334. ellipse ID 0....pic".
  2335. Hiding and showing objects using
  2336. 1.    Display the Command window.
  2337.     Press Shift+F3.
  2338. 2.    Type the following commands in the Command window. Press Enter after each command.
  2339.     hide rectangle "box"
  2340.     show rectangle "box"
  2341.     hide menubar
  2342.     show menubar
  2343.     hide toolpalette
  2344.     show toolpalette
  2345.     move toolpalette to 100,100
  2346. 3.    What commands would you type to hide and show the pattern palette? The color tray?
  2347.     Hint: If you don't know, try using OpenScript Help.
  2348. manual.
  2349. Hiding and showing objects using the Command window
  2350. sectionNumber
  2351. Setting and getting field text i
  2352. 1.    Type the following commands in the Command window. Press Enter after each command:
  2353.     set text of field "thatfield" to text of field "thisfield"
  2354.     clear text of field "thisfield"
  2355.     set text of field "thisfield" to "Hi there!"
  2356.     put the third word of text of field "thatfield"
  2357.     put the last word of text of field "thisfield"
  2358.     put words 4 to 7 of text of field "thatfield"
  2359. 2.    How would you refer to the third through thirteenth characters of field thatfield???ters of field thatfield?"
  2360. 3.    How would you refer to the third through thirteenth characters of field thatfield?
  2361. Setting and getting field text in the Command windowow
  2362. thisfield
  2363. The text of a field is one of its properties just like its border style. and can be set with an OpenScript statement.
  2364. thisfield
  2365. thatfield
  2366. thatfield
  2367. sectionNumber
  2368. ToolBook programming
  2369. ToolBook programminging
  2370. In traditional programs, the program controls the user by requesting input and displaying output..
  2371. PRINT "What's your name?";
  2372. INPUT Name$
  2373. PRINT "Hi, "; Name$
  2374. PRINT "Enter a number: ";
  2375. INPUT Num
  2376. PRINT "The square root of "; Num; " is: "; SQRT(Num)
  2377. FUNCTION Fact(n)
  2378.     f = 1
  2379.     FOR i=2 to n
  2380.         f = f*i
  2381.     NEXT i
  2382.     Fact = f
  2383. END FUNCTIONNNNNNNNNNNNNNNN
  2384. What's your name? Sue
  2385. Hi, Sue
  2386. Enter a number: 4
  2387. The square root of 4 is 2
  2388. startSection
  2389. sectionNumber
  2390. The hierarchy 2
  2391. ontinued
  2392. sectionNumber
  2393. For example, if you click a page object that does not have a handler for the buttonDown message, the message continues to the page, then to the background, and so on, until it reaches the ToolBook system..m.
  2394. The hierarchy, continued....
  2395. Spark
  2396. height
  2397. height
  2398. arrow
  2399. false
  2400. false
  2401. The ToolBook difference
  2402. sectionNumber
  2403. The ToolBook differenceg
  2404. In a ToolBook application, the user controls the program. Everything the user does (like clicking a button) sends a message to an object which runs a "handler" to respond.
  2405. Try to click the objects for which a script is shown.n.
  2406. Number:
  2407. number
  2408. -- When 
  2409. clicked, 
  2410. (the user 
  2411. place 
  2412. ("What 
  2413. x"Cancel" 
  2414. buttonUp
  2415. buttonUp
  2416. What number?
  2417. Cancel
  2418. 81fdas
  2419. to handle buttonUp
  2420.     get text of self
  2421.     ask "What number?" with it
  2422.     if sysError is not "Cancel" then
  2423.         set the text of self to it
  2424. end buttonUpp
  2425. Calculate
  2426. -- When 
  2427. clicked, calculate the square root 
  2428. place results 
  2429. 3"answer" 
  2430. -- The actual 
  2431. here 
  2432. a little more complicated than
  2433. {impler 
  2434. , because 
  2435. also implement
  2436. -- error trapping.
  2437. Our testers had so much fund trying
  2438. , we 
  2439. placate them.
  2440. -- Don't suspend execution 
  2441. r            -- Clear 
  2442. P-- Reset 
  2443. default
  2444. y        -- If there was 
  2445. "Cannot take 
  2446. & n & """!"
  2447. buttonUp
  2448. buttonUp
  2449. number
  2450. answer
  2451. Cannot take the square root of "
  2452. answer
  2453. Calculate
  2454. to handle buttonUp
  2455.     get text of field "number"
  2456.     clear text of field "answer"
  2457.     if it is not null then
  2458.         get sqrt(it)
  2459.         set text of field "answer" to it
  2460. end buttonUp ndld "answer"
  2461. Answer
  2462. Square Root:is:::::
  2463. Name versus ID
  2464. sectionNumber
  2465. Name versus ID
  2466. You can refer to an object using its name, if it has one, or its ID. You can name an object using the Properties dialog box or by setting the Name property for the object. The ID is assigned by ToolBook and is unique for each object. 
  2467. It is usually best to refer to objects by name. When you cut and paste an object, its ID changes, so references to the old ID will be invalid. The name does not change unless you change it...old ID will be invalid. The name does not change unless you change it.ess you change it.
  2468. An object's location
  2469. An object's locationame
  2470. If the object you're referring to isn't on the current page you may have to add location information to refer to it. For example, to refer to a button on the background you might use the following:
  2471. button "Next Page" of background "Database"
  2472. mple shows you the namess of 
  2473. sectionNumber
  2474. Handlers in objects
  2475. sectionNumber
  2476. If the script of the object contains a handler for the buttonDown message, the object's handler is executed and the message stops..
  2477. Handlers in objectsarchy
  2478. Spark
  2479. height
  2480. height
  2481. button script
  2482. to handle buttonDown
  2483.     beep 10
  2484. to handle myMessage
  2485.     go to page "Test"
  2486. end"Test"
  2487. arrow
  2488. -- Animate the message demo 
  2489. showMe
  2490. moveLSpark "et1"
  2491. showMe
  2492. showMe
  2493. moveLSpark
  2494. button script
  2495. button script
  2496. button script
  2497. Ask and request
  2498. Ask and request Commands
  2499. The ask and request commands are useful for getting information or choices from a user. The ask command asks the user to enter some text. Whatever the user types is placed in the special variable, It.
  2500. The request command displays a message and asks the user to click a button in response. The text on the button clicked is placed in the special variable, It.
  2501. in the container, IT.
  2502. startSection
  2503. sectionNumber
  2504. Handling keystrokes
  2505. sectionNumber
  2506. startSection
  2507. Handling keystrokess
  2508. Sometimes you want to respond to a user based on characters he or she types at the keyboard. You can do this with a keyChar handler. One common use of the keyChar handler is to check data as it is typed to make sure it is valid for the field.
  2509. The following exercise shows how to write a keyChar handler to make sure data is numeric.ic.numeric.meric.ic.
  2510. Handlers in pages
  2511. sectionNumber
  2512. If the object does not have a buttonDown handler but the page does, the page's handler is executed and the message stops..................
  2513. Handlers in pagesarchy, cont.
  2514. Spark
  2515. height
  2516. height
  2517. page script
  2518. to handle buttonDown
  2519.     beep 10
  2520. to handle myMessage
  2521.     go to page "Test"
  2522. arrow
  2523. buttU
  2524. -- Animate the message demo 
  2525. showMe
  2526. moveLSpark "et1"
  2527. showMe
  2528. showMe
  2529. moveLSpark
  2530. moveLSpark
  2531. page script
  2532. page script
  2533. page script
  2534. Using the request command
  2535. 1.    Create a button and label it "Decision".
  2536.     Use the button tool from the tool palette.
  2537. 2.    Edit the button's script and type:
  2538.     to handle buttonUp
  2539.         request "Save humanity or not?" with \
  2540.             "Save" or "Destroy"
  2541.         set text of field "fate" to it
  2542.     end buttonUp
  2543. 3.    Switch to Reader level and click the button.
  2544.     Try this a couple of times, making different choices. Which choice is the default choice? Try adding a third choice, "Neither" (remember, you can look in OpenScript Help for information on the request command). What's the difference between ask and request?anual).
  2545. Using the request command
  2546. Fated: fate
  2547. sectionNumber
  2548. To get and to set handlers
  2549. User-defined properties are commonly used to store values. By defining a to get and a to set handler for an object, however, you can create a user-defined property that is much more powerful.
  2550. The following exercise shows how to define a size property for an object such that setting the object's size will cause its bounds to change..
  2551. ndle=
  2552. startSection
  2553. sectionNumber
  2554. To get and to set handlers
  2555. Creating a self-sorting field
  2556. sectionNumber
  2557.     To create a self-sorting field, write a handler in the field's script to handle a user-defined message, such as sortLines. Then, to sort the lines of the field from the Command window, type:
  2558.     send sortLines to field <fieldname>
  2559.     where <fieldname> stands for the name of the field.
  2560. 1.    Create a field.
  2561. 2.    Write a sortLines handler for the field that sorts the field's lines.
  2562.     Remember the terms my and self can be used to refer to the object containing a script. If you want to see one solution, switch to Reader level and click the "Hint" button....Hint button......l and click on the Hint button.....................
  2563. Creating a self-sorting field
  2564. -- Show 
  2565. the hint.
  2566. "Hint"
  2567. buttonUp
  2568. buttonUp
  2569. -- Handler to sort a field. The handler must be 
  2570. -- located in the field's script and is activated by 
  2571. -- sending a sortLines message to the field. This
  2572. -- handler uses a Bubble sort algorithm.
  2573. to handle sortLines
  2574.     get my text
  2575.     set N to textLineCount(it)
  2576.     clear my text
  2577.     step i from N to 2 by -1
  2578.         step k from 1 to i-1
  2579.             if textLine i of it < textLine k of it as text 
  2580.                 set temp to textLine i of it
  2581.                 set textLine i of it to textLine k of it
  2582.                 set textLine k of it to temp
  2583.             end if
  2584.         end step
  2585.     end step
  2586.     set my text to it
  2587. enddd
  2588. Working with Objects from the Co
  2589. Adding Menus and Menu Items
  2590. Creating a Self-Sorting Field
  2591. The ToolBook Difference
  2592. Types of Expressions
  2593. A user-defined function for chec
  2594. OpenScript commands
  2595. Verifying data during input with
  2596. A Self-Sorting Field
  2597. Navigation
  2598. Listing All Objects on a Page
  2599. Moving a Draw Object
  2600. Using the debugger to interrupt 
  2601. Using the debugger to interrupt
  2602. Push and pop
  2603. sectionNumber
  2604. startSection
  2605. Push and pop
  2606. Lists are a powerful feature of ToolBook. The push and pop commands allow you add items to and remove items from a list. Pushing an item places the item at the beginning of the list. Popping an item removes it from the beginning. Try clicking the two "Show" buttons for a demonstration.a demonstration.
  2607. Items
  2608. Three
  2609. Seven
  2610. Show Push
  2611. -- When 
  2612. clicked, 
  2613. the "
  2614. " arrow (
  2615. one pointing 
  2616. Ftake 
  2617. Mlist" 
  2618. . Then, 
  2619. . If there are no lines 
  2620. , display a message 
  2621. that effect.
  2622. "pushArrow"
  2623. "popArrow"
  2624. "Items" 
  2625. . Try popping 
  2626. "List"
  2627. buttonUp
  2628. buttonUp
  2629. pushArrow
  2630. popArrow
  2631. Items
  2632. No items to push. Try popping items first.
  2633. items
  2634. items
  2635. Show Push
  2636. Show Pop
  2637. -- Show the "
  2638. " arrow (
  2639. one pointing 
  2640. 2list" 
  2641. removes 
  2642. places 
  2643. ). If there are no 
  2644. , display a message 
  2645. that effect.
  2646. "pushArrow"
  2647. "popArrow"
  2648. "List" 
  2649. . Try pushing 
  2650. "Items"
  2651. buttonUp
  2652. buttonUp
  2653. pushArrow
  2654. popArrow
  2655. No items to pop. Try pushing items first.
  2656. Items
  2657. Show Pop
  2658. pushArrow
  2659. List:
  2660. Item:
  2661. popArrow
  2662. Navigating in this Book
  2663. Advanced topics
  2664. Popping items from a List
  2665. Handling Key Strokes
  2666. Expressions
  2667. Moving a draw object using the s
  2668. Handling keystrokes
  2669. Navigating in this book
  2670. Navigating in this book
  2671. On explanation pages you can 
  2672. click on the arrow buttons to turn 
  2673. pages. Click the Table of 
  2674. Contents button to return to the 
  2675. table of contents.
  2676. Text on this page explains a topic.cg a topic
  2677. Title
  2678. Explanation Page
  2679. Table of Contents
  2680. Table of Contents
  2681. 8370,5460
  2682. 7764,5464
  2683. startSection
  2684. sectionNumber
  2685. The Command window
  2686. sectionNumber
  2687. startSection
  2688. The Command windowWindow
  2689. Although OpenScript is used most often in writing scripts, it can also be used directly in the Command window to do things that would be difficult or impossible with a menu command or with a mouse.ld be difficult or impossible with a menu. following pages contain exercises using OpenScript and the Command Window...uld be difficult or impossible through a menu. The following pages contain exercises using OpenScript and the Command Window.
  2690. :PHYSSIZE
  2691. User-defined properties
  2692. sectionNumber
  2693. startSection
  2694. User-defined properties
  2695. In addition to an object's built-in properties, you can create your own properties. The following exercise shows an example of creating a user-defined property to store the original bounds of an object so the object can be restored to its original size after its size has been changed.been changed.
  2696. User-defined messages
  2697. sectionNumber
  2698. startSection
  2699. User-defined messages
  2700. Through the use of custom menus, message handlers, and the send command, you can define your own messages and handlers.
  2701. The following exercise shows a simple example of creating a user-defined message and handler. For an example of defining your own menus, see the section on menus.
  2702. Menus
  2703. ontrol
  2704. sectionNumber
  2705. startSection
  2706. Menuslllllll
  2707. You can use OpenScript to customize ToolBook's pull-down menus. You can add or remove menus and menu items as well as change the way ToolBook responds to existing menu items...o existing menu items.
  2708. Message Demo
  2709. -- When entering 
  2710. the speed 
  2711.     ark 
  2712. -- switch 
  2713. level.
  2714. 4s_mLSpeed
  2715. -- Move 
  2716. \message hierarchy animations. The
  2717. $, "What", 
  2718. Ualong which 
  2719. travels.
  2720. -- This handler assumes 
  2721. -- finished moving 
  2722. displays 
  2723. large
  2724. -- splatting spark, "Bing".
  2725. moveLSpark what
  2726. "bing" 
  2727. - height 
  2728. z" / 2
  2729. ackground
  2730. enterbackground
  2731. moveLSpark
  2732. enterbackground
  2733. reader
  2734. s_mLSpeed
  2735. moveLSpark
  2736. height
  2737. spark
  2738. height
  2739. spark
  2740. spark
  2741. spark
  2742. spark
  2743. spark
  2744. s_mLSpeed
  2745. Table of Contents
  2746. -- Return 
  2747. the Table 
  2748. Contents.
  2749. buttonUp
  2750. buttonUp
  2751. Table of Contents
  2752. Table of Contents
  2753. -- If 
  2754. moved, 
  2755. a user-defined property, home, 
  2756. -- the 
  2757. graphic covering 
  2758. -- When 
  2759. Bmouse 
  2760. pressed, 
  2761. released, 
  2762. w. Finally, 
  2763. -- Move 
  2764. -- depending on 
  2765. parameter, x, which can be 
  2766. H15,15
  2767. buttonDown
  2768. moved
  2769. buttonUp
  2770. press
  2771. moved
  2772. buttonDown
  2773. press
  2774. buttonUp
  2775. press
  2776. previous
  2777. press
  2778. 7755,5480
  2779.      
  2780. Right
  2781. -- If 
  2782. moved, 
  2783. a user-defined property, home, 
  2784. -- the 
  2785. graphic covering 
  2786. -- When 
  2787. Bmouse 
  2788. pressed, 
  2789. released, 
  2790. w. Finally, 
  2791. -- Moves 
  2792. sets 
  2793. -- depending on 
  2794. parameter, x, which can be 
  2795. H15,15
  2796. buttonDown
  2797. moved
  2798. buttonUp
  2799. press
  2800. moved
  2801. buttonDown
  2802. press
  2803. buttonUp
  2804. press
  2805. press
  2806. 8370,5475
  2807.      
  2808. ToolBook
  2809. Systemmm
  2810. Background
  2811. MouseButton
  2812. Page Leader
  2813. Title
  2814. Paths
  2815. Show Example
  2816. -- When the mouse 
  2817. pressed, turn 
  2818. -- graphics on 
  2819. 0screen 
  2820. B"mouseButton" 
  2821. "Arrow" 
  2822. released, 
  2823. showMe message 
  2824. animated demo 
  2825. 0,75.3125,0
  2826. buttonDown
  2827. buttonUp
  2828. buttonDown
  2829. mouseButton
  2830. 0,0,0
  2831. Arrow
  2832. 0,0,0
  2833. buttonUp
  2834. showMe
  2835. mouseButton
  2836. Arrow
  2837. 0,100,0
  2838. Show Example
  2839. Looping control structures
  2840. Listing objects continued
  2841. Messages
  2842. Messages
  2843. sectionNumber
  2844. startSection
  2845. Messages Messageslers, Cont.
  2846. A user's actions cause 
  2847. messages to be sent. Each 
  2848. message has a name. For 
  2849. example, clicking an object with
  2850. the mouse causes two messages 
  2851. to be sent to the object: 
  2852. buttonDown and buttonUp.
  2853. Button Message Example
  2854. -- Animate the two 
  2855. Bmessages 
  2856. example.
  2857. doMouse
  2858. B"mouseClick" 
  2859. "downMessage"
  2860.     Move 
  2861. 6435, 2647
  2862. 6390, 2557
  2863. 6300, 2467
  2864. 6210, 2332
  2865. 6120, 2212
  2866. 6045, 2122
  2867. 5910, 1942
  2868. 5745, 1852
  2869. 5565, 1687
  2870. 5430, 1597
  2871. "upMessage"
  2872. 6435, 2647
  2873. 6390, 2557
  2874. 6300, 2467
  2875. 6210, 2332
  2876. 6120, 2212
  2877. 6045, 2122
  2878. 5910, 1942
  2879. 5745, 1852
  2880. 5565, 1687
  2881. 5430, 1597
  2882. doMouse
  2883. doMouse
  2884. mouseClick
  2885. downMessage
  2886. button
  2887. mouseClick
  2888. upMessage
  2889. button
  2890. matte
  2891. button
  2892. inverse
  2893. false
  2894. arrow
  2895. mouseClick
  2896. inverse
  2897. upMessage
  2898. buttonUp
  2899. downMessage
  2900. buttonDown
  2901. Show Example
  2902. -- Send a doMouse message 
  2903. the grouped 
  2904. example," 
  2905. animate 
  2906. "Button Message Example"
  2907. buttonUp
  2908. buttonUp
  2909. FdoMouse
  2910. Button Message Example
  2911. Show Example
  2912. arning ToolBook
  2913. System
  2914. enScript Exercises
  2915. s Rmn
  2916. `D|D|
  2917. -- a 
  2918. renumbering a 
  2919. n > 0 
  2920. enterBook
  2921. renumber
  2922. enterBook
  2923. sizeToPage
  2924. renumber
  2925. :REPORTDATA
  2926. :CONDITIONDATA
  2927. Text of RecordField "Instructions" is "null" As Text
  2928. Text of RecordField "Instructions" is null
  2929. OpenScript Workbook
  2930. System
  2931. y`D|D|
  2932. `D|D|
  2933. ]D|D|
  2934. gD|D|
  2935. \D|D|
  2936. `D|D|
  2937. `D|D|
  2938. `D|D|
  2939. `D|D|
  2940. `D|D|
  2941. `D|D|
  2942. rminal
  2943. `D|D|
  2944. `D|D|
  2945. `D|D|
  2946. fault
  2947. 9_D|D|
  2948. pageNumber is 103 or pageNumber is 104
  2949. pageNumber is 103 or pageNumber is 104
  2950. pageNumber is 103 or pageNumber is 104
  2951. pageobjs
  2952. `D|D|
  2953. :PRINTLAYOUT
  2954. `D|D|
  2955. `D|D|
  2956. u`D|D|
  2957. 3^D|D|
  2958. \D|D|
  2959. \D|D|
  2960. \D|D|
  2961. Title
  2962. Instructions
  2963. "QuikTour"
  2964. "OSWorkBk"
  2965. "~pUnable 
  2966. Quick 
  2967. enterBook
  2968. previous
  2969. author
  2970. leaveBook
  2971. enterBook
  2972. reader
  2973. sizeToPage
  2974. s_launchedFrom
  2975. author
  2976. o MmenuPop
  2977. previous
  2978. o MmenuPop
  2979. leaveBook
  2980. QuikTour
  2981. OSWorkBk
  2982. QuikTour.v
  2983. ~pUnable to return to the Quick Tour.
  2984. launchedFrom
  2985. s_launchedFrom
  2986. exercise
  2987. Instructions
  2988. Title
  2989. To turn the page, press Ctrl+Right Arrow.............................................
  2990. -- Make sure ToolBook 
  2991. )Author level 
  2992. )the beginning
  2993. each exercise.
  2994. enterPage
  2995. enterPage
  2996. Author
  2997. author
  2998. Control structures
  2999. Control structures
  3000. OpenScript contains several control structures for both branching and looping within a script. The following pages show some examples of the branching and looping control structures. These are followed by exercises.es.
  3001. startSection
  3002. sectionNumber
  3003. User-defined messages 1
  3004. sectionNumber
  3005.     In this exercise, the button, "Send message," sends a user-defined message to the rectangle. The rectangle has a handler that responds to the message.
  3006. 1.    Type the following two commands in the Command window, pressing Enter after each command:
  3007.      set script of rectangle "rec" to text of field "script1"
  3008.      set script of button "send" to text of field "script2"
  3009.     This copies the scripts into the two objects
  3010. 2.    Switch to Reader level and click the "Send Message" button.
  3011. 3.    Create another user-defined message called "changeColor" that causes the rectangle to turn red then back to white.ar.
  3012. User-defined messagess
  3013. Send message
  3014. script1
  3015. to handle hideAndShow
  3016.         hide self
  3017.         pause 2 seconds
  3018.         show self
  3019. y fillcolor to white
  3020. end blush
  3021. script2
  3022. to handle buttonUp
  3023.         send hideAndShow to rectangle "rec"
  3024. endUpp
  3025. Script11
  3026. Script22
  3027. ect so t
  3028. Drawing objects from a script
  3029. sectionNumber
  3030.     In this exercise you will write a script to draw a rectangle.
  3031. 1.    Edit the script of the button, "Draw Square".
  3032. 2.    Look at the draw command in OpenScript Help.
  3033. 3.    Create a buttonUp handler to draw a rectangle from 6000,900 to 7500,2400.
  3034.     For a hint, switch to Reader level and click the "Hint" button.
  3035. 4.    Switch to Reader level and try the button.
  3036. 5.    Try drawing an ellipse or polygon.
  3037. Drawing objects from a script
  3038. Draw Square
  3039. Draw Square
  3040. to handle buttonUp
  3041.     draw rectangle from 6000,900 to \
  3042.         7500,2400
  3043.     set the fillcolor of the selection to blue
  3044. end buttonUpppppppppppppppp
  3045. -- Show 
  3046. the hint.
  3047. "Hint"
  3048. buttonUp
  3049. buttonUp
  3050. A simple object browser using ri
  3051. sectionNumber
  3052.     In this exercise you will write a handler that displays information on an object when it is clicked with the right mouse button. To prepare, look at the rightButtonClick message and the objectFromPoint function in OpenScript Help.
  3053. 1.    Write a handler for the page that uses the request command to display an object's ID, name and parent when the object is clicked with the right mouse button. 
  3054.     For a hint, switch to Reader level and click the "Hint" button. 
  3055. 2.    Test your script by switching to Reader level and clicking objects on the page with the right mouse button.
  3056.     Why doesn't clicking background objects work? Try modifying the handler to edit the script of an object when it is clicked with right mouse button.ked with right mouse button.ht mouse button. mouse button..button.
  3057. A simple object browser using rightButtonClick
  3058. blank hint
  3059. to handle rightButtonUp loc, isShift, isCtrl
  3060.     get objectFromPoint(loc)
  3061.     if it is not null
  3062.         clear objInfo
  3063.         put "Object:" & TAB & it & CRLF after objInfo
  3064.         put "Name:" & TAB & name of it & CRLF \
  3065.             after objInfo
  3066.         put "Parent:" & TAB & parent of it & CRLF \
  3067.             after objInfo
  3068.         request objInfo
  3069. end rightButtonUpppppppppppppppppppppppt onto x
  3070.         end
  3071. end buttonUpp
  3072. -- Show 
  3073. the hint.
  3074. "Hint"
  3075. buttonUp
  3076. buttonUp
  3077. Red Ellipse
  3078. Slice of Blueberry
  3079. Click Me
  3080. -- Move the 
  3081. B50 steps 
  3082. S. Each
  3083. units (1/1440 
  3084. inch). When finished, 
  3085. -starting 
  3086. which was saved 
  3087. -- "home" user-defined property.
  3088. H-30, 0
  3089. buttonUp
  3090. buttonUp
  3091. Click Me
  3092. Square
  3093. Moving a draw object
  3094. sectionNumber
  3095.     In this exercise you will write a script to move 
  3096.     the red dot around the screen.
  3097. 1.    Edit the script of the button "Fun With Dot" and create a buttonUp handler to move the dot to the following points:
  3098.     8000, 100
  3099.     8000, 4000
  3100.     6300, 2050
  3101.     4600, 4000
  3102.     4600, 100
  3103.     Use any order you want. For one solution, switch to Reader level and click the "Hint" button.......
  3104. Moving a draw object
  3105. funbutton
  3106. Fun With Dot
  3107.  to handle buttonUp
  3108.          move ellipse "dot" to 8000,100
  3109.         move ellipse "dot" to 8000,4000
  3110.         move ellipse "dot" to 6300, 2050
  3111.         move ellipse "dot" to 4600,4000
  3112.         move ellipse "dot" to 4600,100
  3113. end buttonUppttonUppppppppppppnUp
  3114. -- Show 
  3115. the hint.
  3116. "Hint"
  3117. buttonUp
  3118. buttonUp
  3119. Changing an object's color prope
  3120. sectionNumber
  3121.     In this exercise there are three ellipses: "scoop", on top of the cone; "Vanilla", on top of the vanilla tub and "Chocolate", on top of the chocolate tub. The script displayed in the white field shows how the color of the scoop ellipse (its fillColor property) can be set to the fillColor of "Chocolate" or "Vanilla".
  3122. 1.    Look at the script. Which lines change the fillColor property of the ellipse, "scoop"?
  3123.     This is the script of the button labeled "Chocolate or Vanilla?"
  3124. 2.    Switch to Reader level and click the button.
  3125.     Try again with the other flavor...the other flavor..r..avor..n the button.
  3126.     Try it again with the other flavor..hen switch back to Author level.
  3127. Changing an object's color properties
  3128. scoop
  3129. vanilla
  3130. chocolate
  3131. Flavor
  3132. -- Use the 
  3133. a choice 
  3134. flavor 
  3135. -- user, 
  3136. ."scoop" 
  3137. accordingly.
  3138. "What 
  3139. @would you like?" 
  3140.     "Chocolate" 
  3141. "Vanilla"
  3142. buttonUp
  3143. buttonUp
  3144. What flavor would you like?
  3145. Chocolate
  3146. Vanilla
  3147. Chocolate
  3148. scoop
  3149. Chocolate
  3150. scoop
  3151. Vanilla
  3152. Chocolate or Vanilla?
  3153. Script1
  3154. to handle buttonUp
  3155.     request "What flavor would you like?" with \
  3156.     "Chocolate" or "Vanilla"
  3157.     if It is Chocolate
  3158.         set the fillcolor of ellipse "scoop" to the \
  3159.         fillcolor of ellipse "Chocolate"
  3160.     else
  3161.         set the fillcolor of ellipse "scoop" to the \
  3162.         fillcolor of ellipse "Vanilla"
  3163.     end if
  3164. end buttonUpttonUptonUpttonUptonUpttonUppppppp
  3165. Moving a draw object using the s
  3166. sectionNumber
  3167.     The step control structure can be used for animation. In this exercise it is used for moving the red dot around the screen.
  3168. 1.    Edit the script of the button, "Fun with Dot".
  3169. 2.    Create a buttonUp handler to move the dot to the bottom of the screen and back.
  3170.     The starting position is 7750, 100 and the ending position is 7750, 5000. One way to write this handler is to use the step control structure and the move command. For information on these, see OpenScript Help. To see one solution, switch to Reader level and click the "Hint" button.
  3171. 3.    How could you move the dot in a square around the screen?en? screen??
  3172. Moving a draw object using the step control structure
  3173. to handle buttonUp
  3174.     move ellipse "dot" to 7750, 100
  3175.     step yPos from 100 to 5000 by 100
  3176.         move ellipse "dot" to 7750, yPos
  3177.     end step
  3178.     step yPos from 5000 to 100 by -100
  3179.         move ellipse "dot" to 7750, yPos
  3180.     end step
  3181. end buttonUp 0,var2
  3182.         end step
  3183.         step var3 from 300 to 1 by -10
  3184.               move ellipse "dot" by var3,0
  3185.         end step
  3186. end buttonUpW
  3187. -- Show 
  3188. the hint.
  3189. "Hint"
  3190. buttonUp
  3191. buttonUp
  3192. Fun with Dot
  3193. A buttonUp handler higher in the
  3194.     One way to handle clicking an object is to
  3195.     place a handler in the object's script. With 
  3196.     lots of similar objects, this can mean lots 
  3197.     of similar handlers. Using the target property, you can write a single handler on the page that handles clicking all of the similar page objects.
  3198. 1.    Edit the page script and enter the script you see to the right.
  3199. 2.    Switch to Reader level and click one of the states in the map.
  3200.     The buttonDown message is first sent to the state you click, a draw object. The object is recorded in the target property. The message is passed on to the group ("map"), then to the page. The page has a handler for the message that puts the name of the target (the state you clicked) into the "State Name" field.    
  3201. sectionNumber
  3202. A buttonUp handler higher in the hierarchyyy
  3203. State Name
  3204. Washington
  3205. Montana
  3206. Oregon
  3207. California
  3208. Nevada
  3209. Idaho
  3210. Wyoming
  3211. Arizona
  3212. New Mexico
  3213. Colorado
  3214. Texas
  3215. Oklahoma
  3216. Kansas
  3217. Nebraska
  3218. South Dakota
  3219. North Dakota
  3220. Minnesota
  3221. Missouri
  3222. Arkansas
  3223. Louisiana
  3224. Wisconsin
  3225. Illinois
  3226. Kentucky
  3227. Indiana
  3228. Tennessee
  3229. Mississippi
  3230. Alabama
  3231. Georgia
  3232. Florida
  3233. North Carolina
  3234. South Carolina
  3235. Michigan
  3236. Pennsylvania
  3237. West Virginia
  3238. Virginia
  3239. Maryland
  3240. Delaware
  3241. New York
  3242. New Jersey
  3243. Vermont
  3244. New Hampshire
  3245. Maine
  3246. Massachusetts
  3247. Connecticut
  3248. Rhode Island
  3249. Alaska
  3250. Hawaii
  3251. Hawaii
  3252. Hawaii
  3253. Hawaii
  3254. Hawaii
  3255. script1
  3256. to handle buttonDown
  3257.         set text of field "State Name" to name of target
  3258. end buttonDown
  3259. to handle buttonUp
  3260.         set the text of field "State Name" to null
  3261. end buttonUpppppppppp
  3262. A user-defined function for sort
  3263. sectionNumber
  3264.     Although lists are a powerful feature in ToolBook, there are no built-in functions for sorting lists. In this exercise, you will write a function to sort a list of text items. The following is one method for sorting a list:
  3265.     While the original list still has items in it,
  3266.         Find the largest item in the list
  3267.         Push that item onto the sorted list
  3268.         Clear that item from the original list
  3269. 1.    Edit the script of this page and write a handler that sorts a list. Call the function "sortList" and give it one parameter, the list to be sorted.
  3270.     Click the "Hint" button for one solution.
  3271. 2.    Test the function by clicking the "Sort Test" button.
  3272.     " button.
  3273.     e options menu when the debugger is displayed.......
  3274. A user-defined function for sorting a listto a dateage
  3275. to get sortList list
  3276.     clear sortedList
  3277.     while list is not null
  3278.         set biggest to 1
  3279.         step i from 2 to itemCount(List)
  3280.             get item i of list
  3281.             if it > item biggest of list as text
  3282.                 set biggest to i
  3283.             end
  3284.         end
  3285.         push item biggest of list onto sortedList
  3286.         clear item biggest of list
  3287.     return sortedList
  3288. Sort Test
  3289. ("Type the list you want 
  3290.         "z,y,x,w,v,u,t,s,r,q,p,o,n,m,l,k,j,i,h,g,f,e,d,c,b,a"
  3291. "The sorted 
  3292. :" & CRLF & sortList(
  3293. buttonUp
  3294. buttonUp
  3295. Type the list you want to sort:
  3296. z,y,x,w,v,u,t,s,r,q,p,o,n,m,l,k,j,i,h,g,f,e,d,c,b,a
  3297. The sorted list is:
  3298. sortList
  3299. Sort Test
  3300. -- Show 
  3301. the hint.
  3302. "Hint"
  3303. buttonUp
  3304. buttonUp
  3305.     used
  3306. FxZoom fxDissolve and fxWipe
  3307. -- When a sample 
  3308. clicked, install the 
  3309. "Effect" 
  3310. c"Script" 
  3311. buttonUp
  3312. buttonUp
  3313. field
  3314. Script
  3315. 180,50,100
  3316. Effect
  3317. 0,100,0
  3318. sectionNumber
  3319.     This exercise shows the effect of the different "fx" commands when changing pages. There are three scripts. Clicking on each one at Reader level will install it in the "Effect" button.
  3320. 1.    Switch to Reader level.
  3321.     Most messages aren't sent at Author level.
  3322. 2.    Click one of the scripts.
  3323.     This puts the script in the "Effect" button.
  3324. 3.    Click the "Effect" button.
  3325. 4.    Try it with the other scripts.
  3326. 5.    Make up an effect script of your own.
  3327. ript2, switch to Reader level and click the button.
  3328. 5.    Switch back to Author level and use the Command window to set the script of the button to the text of samplescript3, then switch to Reader level and click the button.
  3329. FxZoom, fxDissolve and fxWipe
  3330. Landscape
  3331. Effect
  3332. Effect
  3333. script3
  3334. to handle buttonUp
  3335.     fxDissolve slow to next page
  3336. end buttonUputtonUp#
  3337. script2
  3338. to handle buttonUp
  3339.     fxZoom to next page at sysmouseposition
  3340. end buttonUpppppppppp
  3341. script1
  3342. to handle buttonUp
  3343.     fxWipe left to gray
  3344.     fxWipe right to next page
  3345. end buttonUpd buttonUpd buttonUp
  3346. buttonUp
  3347. buttonUp
  3348. fx destination
  3349. -- When entering the 
  3350. , switch 
  3351. Reader level.
  3352. enterPage
  3353. enterPage
  3354. Reader
  3355. sectionNumber
  3356.     You made it!
  3357.     Click the "Go Back" button to return to the previous page.
  3358.     ! 4    
  3359. -- Go 
  3360. buttonUp
  3361. buttonUp
  3362. Go Back
  3363. "used
  3364. "true
  3365. OWORKBK.ico
  3366. DDDDD
  3367. DDDDDDDDD
  3368. ]4]4]4
  3369.