Download Learning ZIL
Transcript
Page 21 Learning ZIL 2/25/2002 Ten turns from now, the interrupt routine called I-SHOOTING-STAR will be called by CLOCKER, and will do whatever it is set up to do. An interrupt routine which is queued to 1 will run on the same turn, before the very next prompt. An interrupt which is queued to 2 will run after the following turn, and so forth. An interrupt runs only once, and then isn't heard from again unless you requeue it. However, there is one important exception: if you queue an interrupt to -1, the interrupt will run every turn from then on, until you dequeue it. A routine is dequeued simply by saying <DEQUEUE I-WHATEVER>. An example of a routine queued to -1 would be the truck interrupt which was used as an example in section 4.2. In conjunction with a global variable called TRUCK-COUNTER, initially set to a value of zero, the routine might look like this: <ROUTINE I-TRUCK () <SETG TRUCK-COUNTER <+ ,TRUCK-COUNTER 1>> <COND (<EQUAL? ,TRUCK-COUNTER 1> <MOVE ,TRUCK ,STREET> <TELL "A truck begins speeding toward you." CR>) (<EQUAL? ,TRUCK-COUNTER 2> <TELL "The truck loudly honks its horn." CR>) (<EQUAL? ,TRUCK-COUNTER 3> <COND (<EQUAL? ,HERE ,STREET> <JIGS-UP "Since you refuse to move out of the way, the truck merges you into the pavement.">) (T ;"you've gotten out of the way" <TELL "The truck blasts you with hot exhaust fumes as it rumbles past." CR>) (T ;"counter is 4" <DEQUEUE I-TRUCK> <SETG TRUCK-COUNTER 0> <TELL "The truck vanishes in the direction of Hoboken." CR>)>> Notice the first item, where 1 is added to the value of TRUCK-COUNTER. This enables I-TRUCK to "know" how far through the truck sequence it is. Also, notice the routine called JIGS-UP, which is being passed a string as an argument. This notorious routine is the routine which "kills" the player; it prints the string which gets passed to it, followed by something like "*** You have died ***." The JIGS-UP occurs only if the player remains in the street. Otherwise, the second part of that COND occurs, with the text about the truck rumbling (safely) past. Finally, notice that the last predicate in the main COND is simply T. This is a predicate which is always true; anytime the COND reaches that point, the stuff in that clause will be executed. In this case, that will happen whenever TRUCKCOUNTER is 4. In addition to turning itself off using DEQUEUE, notice that