Subject: Automatic attract loop

Here is a way to make a book that shows a series of pages, but responds to a click while pausing on a page. After a set time out on the last page, it returns to the first page. The method shown here uses idle, which is less efficient but works with any version of ToolBook.

A) In the script of the book, put the following handlers:

       to handle enterBook
            system s_DoAttractLoop -- use to turn the attract loop behavior on or off
            send reader
            forward
            set sysTimeFormat to "seconds"
             set s_DoAttractLoop to true
        end
       to handle enterPage
             system s_TimeToGo, s_DoAttractLoop
             forward
             if s_DoAttractLoop is true
                 get PageTime of this page
                 if it <> null and sysLevel is reader
                     set sysTimeFormat to "seconds"
                     set s_timeToGo to sysTime + PageTime of this page
                 end
            end
       end
       to handle leavePage
             system s_TimeToGo; clear s_TimeToGo
             forward
       end
       to handle idle
             system s_TimeToGo
             if s_TimeToGo <> null and sysTime >= s_TimeToGo
                     send next to this page
             end
        end
        to handle buttonDown
               system s_TimeToGo, s_DoAttractLoop
               forward
               clear s_TimeToGo
               s_DoAttractLoop = false
                       -- to avoid automatic time out when user navigates
                       -- to other pages that have a PageTime value
        end
B) Assign a system property "PageTime" to each page that should time out automatically. The value of the property is the time in seconds (+ or - 1 second) you want to stay on the page, or null if the page should not have that behavior. You can do this with the command window; for example: set PageTime of page 1 to 6

C) In the last page of the attract loop, add the following handler:

        to handle next
            system s_TimeToGo
            if sysLevel is reader and s_TimeToGo <> null
                 send first -- to go back to the first page
            else
                 forward
            end
        end
That's it! Clicking anything on a page will cause the timeout to be cancelled for that page. You might use two time out values: one while running in attract mode, and one to time out automatically and resume the loop after a long period of inactivity on *any* page in the book. You could use a timer to set the s_DoAttractLoop variable back to true and go back to the first page. But that's another story...

-- Claude Ostyn, Asymetrix


Revised 18/8/95
brianp@u.washington.edu (Brian Parkhurst)
University of Washington
Box 357260
Seattle, WA 98195-7260
206/543-9175