home *** CD-ROM | disk | FTP | other *** search
/ 1,000 Games / 1000GAME.iso / games / winrob12 / events.prg < prev    next >
Text File  |  1995-03-16  |  6KB  |  152 lines

  1. #############################################################################
  2. #                                  EVENTS                                   #
  3. #                                                                           #
  4. # This robot demonstrates the basics of events, priorites, and debugging.   #
  5. # Just follow the path of events and handlers to get the feel for events.   #
  6. # Equally important is the demonstration of print() statements to trace     #
  7. # what the robot is doing. This is a VERY important debugging               #
  8. # technique. Especially when dealing with events, it can be difficult to    #
  9. # determine what robot code is executing, and how it got there.             #
  10. #                                                                           #
  11. # NOTICE: In all the code below this:     flag == TRUE                      #
  12. #         Could be replaces by this:      flag                              #
  13. #                                                                           #
  14. #                                                                           #
  15. #                                                                           #
  16. #   EXECUTION RESULTS                                                       #
  17. #   ~~~~~~~~~~~~~~~~~                                                       #
  18. #                                                                           #
  19. #   Entering Event Robot                                                    #
  20. #   Event group 1 not true yet                                              #
  21. #   Called higher priority event group 1                                    #
  22. #   1.0                                                                     #
  23. #   Ending higher priority event group 1                                    #
  24. #   Returned from event group 1                                             #
  25. #   0.0                                                                     #
  26. #   Event group 2 not true yet                                              #
  27. #   Called lower priority event 2                                           #
  28. #   1.0                                                                     #
  29. #   0.0                                                                     #
  30. #   1.0                                                                     #
  31. #   Called higher priority event group 2                                    #
  32. #   1.0                                                                     #
  33. #   1.0                                                                     #
  34. #   1.0                                                                     #
  35. #   Called higher priority event group 1                                    #
  36. #   1.0                                                                     #
  37. #   Ending higher priority event group 1                                    #
  38. #   Ending higher priority event group 2                                    #
  39. #   Ending lower priority event group 2                                     #
  40. #   Finally, called lowest priority event group 2                           #
  41. #   0.0                                                                     #
  42. #   0.0                                                                     #
  43. #   1.0                                                                     #
  44. #   Ending lowest priority event group 2                                    #
  45. #   Returned from event group 2                                             #
  46. #   0.0                                                                     #
  47. #   0.0                                                                     #
  48. #   0.0                                                                     #
  49. #   Leaving Event Robot  <-- Only after robot is killed!                    #
  50. #                                                                           #
  51. #############################################################################
  52.                                                       
  53. Init
  54. {
  55.     Name( "Events" )
  56.     Print( "Entering Event Robot" )
  57.     
  58.  
  59.     flag1 = FALSE
  60.     
  61.     RegCustom( handler1, 1, flag1 == TRUE )
  62.     RegCustom( handler2, 2, flag1 == TRUE )
  63.     Print( "Event group 1 not true yet" )
  64.  
  65.     flag1 = TRUE
  66.     Print( "Returned from event group 1" )
  67.     Print( flag1 )
  68.     
  69.     flag2 = FALSE
  70.     flag3 = FALSE
  71.     flag4 = FALSE
  72.  
  73.     RegCustom( cascade1, 3, flag2 == TRUE and flag3 == TRUE )
  74.     RegCustom( cascade2, 4, flag2 == TRUE or flag3 == TRUE )
  75.     RegCustom( cascade3, 5, flag4 == TRUE )
  76.     Print( "Event group 2 not true yet" )
  77.     
  78.     flag2 = TRUE
  79.     Print( "Returned from event group 2" )
  80.     Print( flag2 )
  81.     Print( flag3 )
  82.     Print( flag4 )
  83.     
  84. }
  85.  
  86. Handler1
  87. {
  88.     Print( "Called higher priority event group 1" )
  89.     Print( flag1 )
  90.  
  91.     # Notice that ending the event here still
  92.     # allows the rest of the handler to finish!
  93.     flag1 = FALSE
  94.  
  95.     
  96.     Print( "Ending higher priority event group 1" )
  97. }
  98.  
  99. Handler2
  100. {
  101.     Print( "Called lower priority event group 1" )
  102.     Print( "Ending lower priority event group 1" )
  103. }
  104.  
  105. Cascade1
  106. {
  107.     Print( "Called higher priority event group 2" )
  108.     Print( flag2 )
  109.     Print( flag3 )
  110.     Print( flag4 )
  111.     
  112.     # Watch this
  113.     flag1 = TRUE
  114.     Print( "Ending higher priority event group 2" )
  115.     
  116.     flag3 = FALSE
  117. }
  118.  
  119. Cascade2
  120. {
  121.  
  122.     Print( "Called lower priority event group 2" )
  123.     
  124.     # Note that Cascade3 is not called until later since
  125.     # higher priority events are currently in control.
  126.     flag4 = TRUE
  127.     
  128.     Print( flag2 )
  129.     Print( flag3 )
  130.     Print( flag4 )
  131.  
  132.     flag3 = TRUE
  133.  
  134.     Print( "Ending lower priority event group 2" )
  135.     flag2 = FALSE
  136. }
  137.  
  138. Cascade3
  139. {
  140.     Print( "Finally, called lowest priority event group 2" )
  141.     Print( flag2 )
  142.     Print( flag3 )
  143.     Print( flag4 )
  144.  
  145.     flag4 = FALSE
  146.     Print( "Ending lowest priority event group 2" )
  147. }
  148.  
  149. Dead
  150. {
  151.     Print( "Leaving Event Robot" )
  152. }