Script Classes for Adventure Games/Script Class

From SCI Wiki
Jump to: navigation, search

Official SCI Documentation

Chapter: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14
15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | Index

The Script Class

Author: Jeff Stephenson

Date: 5 April 1988


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.

In file:
Inherits from: Object
Inherited by: none



The object (a Prop, Actor, Ego, Room, etc.) whose Script this is. Used to communicate with the Script's client.


The state of the Script.


The desired initial state of the Script.


The ID of a timer which has been set to cue: the Script after a certain interval.


A 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.


The is where the Script keeps the ID of the object to cue: upon completion.


This 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.


This 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.


The 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: newState

Change 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:
(method (changeState newState)
     (switch (= state newState)
          transition code...


Do a changeState: to the next state. Default is to invoke (self changeState:(+ state 1))

handleEvent: event

This 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 register

A 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.




Table of Contents


< Previous: The Inventory Class Next: The Timer Class >