Script Classes for Adventure Games/Script Class
Author: Jeff Stephenson
The Script Class
A Script is a kind of Object which has a state, methods to change that state, and code to execute when the state changes. It is used to model a sequence of actions which should be executed by an object, such as an Actor walking to the base of some stairs, walking up the stairs, and opening a door.
clientThe object (a Prop, Actor, Ego, Room, etc.) whose Script this is. Used to communicate with the Script's client.
stateThe state of the Script.
startThe desired initial state of the Script.
timerThe ID of a timer which has been set to cue: the Script after a certain interval.
registerA property that allows you to store what ever you want. This is very useful in a Script since a temporary variable will not hold its value longer that the life of one method, thus without this property the only way to keep a value fro. state to state through a Script would have been a local o. global variable. If more than one value needs to be stored the register property could be used as a pointer to a Collection, List or Set.
callerThe is where the Script keeps the ID of the object to cue: upon completion.
secondsThis contains the number of seconds until a state change wil. occur. This is generally set in one of the scripts states to signal the number of seconds until a state change should occur.
cyclesThis contains the number of animation cycles until a stat. change will occur. This is generally set in one of the script. states to signal the number of animation cycles until a stat. change should occur.
scriptThe ID of this script's script if it has one. This property is filled by the setScript method and should not be set directly.
init: [client]Initialize the Script entering the initial state by doing a (self changeState:start). Set the Script's client to client if present.
changeState: newStateChange the Script's state to newState. This method is where to put the code to be executed on state transitions. It should store the new state in the state property, then switch to the appropriate code based on the new state:Code:(method (changeState newState) (switch (= state newState) transition code... ) )
cue:Do a changeState: to the next state. Default is to invoke (self changeState:(+ state 1))
handleEvent: eventThis method of an active script is called whenever there is an input event (see class Event). If (event claimed:) is TRUE, someone else has already responded to the event. Whether or not someone else has responded, if the Script responds to the event it should claim it by doing an (event claimed:TRUE). This method ca. be used to add additional responses to an Actor ,Prop etc.
setScript: newScript whoCares registerA Script can also have a script. This adds subroutine style capability to scripts. If the optional parameter whoCares is present the newScript will cue: whoCares and pass on the content. its register when it is disposed (i.e. (client cue:register)). In this case, the last state of the newScript should dispose o. itself i.e. (self dispose:) or (client setScript:0). The third parameter (if present) sets the newScript's register property. If a Script has a newScript the newScript will receive all the events the the parenet script receives.