Difference between revisions of "Script Classes for Adventure Games/Script Class"
(6 intermediate revisions by the same user not shown) | |||
Line 4: | Line 4: | ||
Chapter: | Chapter: | ||
[[Script Classes for Adventure Games/Introduction|1]] | | [[Script Classes for Adventure Games/Introduction|1]] | | ||
− | [[Script Classes for Adventure Games/RootObj|2]] | | + | [[Script Classes for Adventure Games/RootObj Class|2]] | |
− | [[Script Classes for Adventure Games/Object|3]] | | + | [[Script Classes for Adventure Games/Object Class|3]] | |
− | [[Script Classes for Adventure Games/Collection|4]] | | + | [[Script Classes for Adventure Games/Collection Class|4]] | |
− | [[Script Classes for Adventure Games/ | + | [[Script Classes for Adventure Games/Script Class|5]] | |
− | [[Script Classes for Adventure Games/ | + | [[Script Classes for Adventure Games/Timer Class|6]] | |
− | [[Script Classes for Adventure Games/ | + | [[Script Classes for Adventure Games/Feature Class|7]] | |
− | [[Script Classes for Adventure Games/ | + | [[Script Classes for Adventure Games/View Class|8]] | |
− | [[Script Classes for Adventure Games/ | + | [[Script Classes for Adventure Games/PicView Class|9]] | |
− | [[Script Classes for Adventure Games/ | + | [[Script Classes for Adventure Games/Cycling Classes|10]] | |
− | [[Script Classes for Adventure Games/ | + | [[Script Classes for Adventure Games/Motion Classes|11]] | |
− | [[Script Classes for Adventure Games/ | + | [[Script Classes for Adventure Games/Avoider Class|12]] | |
− | [[Script Classes for Adventure Games/ | + | [[Script Classes for Adventure Games/Event Class|13]] | |
− | [[Script Classes for Adventure Games/ | + | [[Script Classes for Adventure Games/User Class|14]]<br /> |
− | + | [[Script Classes for Adventure Games/Game Class|15]] | | |
− | + | [[Script Classes for Adventure Games/Locale Class|16]] | | |
− | + | [[Script Classes for Adventure Games/Region Class|17]] | | |
− | + | [[Script Classes for Adventure Games/Room Class|18]] | | |
− | + | [[Script Classes for Adventure Games/Timer2 Class|19]] | | |
− | + | [[Script Classes for Adventure Games/InvItem Class|20]] | | |
− | + | [[Script Classes for Adventure Games/Block Class|21]] | | |
− | + | [[Script Classes for Adventure Games/Cage Class|22]] | | |
− | + | [[Script Classes for Adventure Games/Sound Class|23]] | | |
− | + | [[Script Classes for Adventure Games/StatusLine Class|24]] | | |
− | + | [[Script Classes for Adventure Games/File Class|25]] | | |
− | + | [[Script Classes for Adventure Games/Code Class|26]] | | |
− | + | [[Script Classes for Adventure Games/Global Variables|27]] | | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | [[Script Classes for Adventure Games/Game| | ||
− | [[Script Classes for Adventure Games/Locale| | ||
− | [[Script Classes for Adventure Games/Region| | ||
− | [[Script Classes for Adventure Games/Room| | ||
− | [[Script Classes for Adventure Games/Timer2| | ||
− | |||
− | [[Script Classes for Adventure Games/InvItem| | ||
− | [[Script Classes for Adventure Games/Block| | ||
− | [[Script Classes for Adventure Games/Cage| | ||
− | [[Script Classes for Adventure Games/Sound| | ||
− | [[Script Classes for Adventure Games/StatusLine| | ||
− | [[Script Classes for Adventure Games/File| | ||
− | [[Script Classes for Adventure Games/Code| | ||
− | [[Script Classes for Adventure Games/Global Variables| | ||
[[Script Classes for Adventure Games/Index|Index]] | [[Script Classes for Adventure Games/Index|Index]] | ||
</div><br /> | </div><br /> | ||
Line 62: | Line 39: | ||
| | ||
− | + | ==<br /> 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. | ||
+ | |||
+ | {| | ||
+ | |width+ "125"|In file:||system.sc | ||
+ | |- | ||
+ | |Inherits from:||Object | ||
+ | |- | ||
+ | |Inherited by:||none | ||
+ | |} | ||
+ | |||
+ | ===<br /> Properties === | ||
+ | |||
+ | <blockquote> | ||
+ | ====<br /> client ==== | ||
+ | <blockquote>The object (a Prop, Actor, Ego, Room, etc.) whose Script this is. Used to communicate with the Script's client.</blockquote> | ||
+ | |||
+ | ====<br /> state ==== | ||
+ | <blockquote>The state of the Script.</blockquote> | ||
+ | |||
+ | ====<br /> start ==== | ||
+ | <blockquote>The desired initial state of the Script.</blockquote> | ||
+ | |||
+ | ====<br /> timer ==== | ||
+ | <blockquote>The ID of a timer which has been set to cue: the Script after a certain interval.</blockquote> | ||
+ | |||
+ | ====<br /> register ==== | ||
+ | <blockquote>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.</blockquote> | ||
+ | |||
+ | ====<br /> caller ==== | ||
+ | <blockquote>The is where the Script keeps the ID of the object to cue: upon completion.</blockquote> | ||
+ | |||
+ | ====<br /> seconds ==== | ||
+ | <blockquote>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.</blockquote> | ||
+ | |||
+ | ====<br /> cycles ==== | ||
+ | <blockquote>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.</blockquote> | ||
+ | |||
+ | ====<br /> script ==== | ||
+ | <blockquote>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.</blockquote> | ||
+ | </blockquote> | ||
+ | |||
+ | ===<br /> Methods === | ||
+ | |||
+ | <blockquote> | ||
+ | ====<br /> init: [client] ==== | ||
+ | <blockquote>Initialize the Script entering the initial state by doing a (self changeState:start). Set the Script's client to client if present.</blockquote> | ||
+ | |||
+ | ====<br /> changeState: newState ==== | ||
+ | <blockquote>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: | ||
+ | |||
+ | <blockquote> | ||
+ | <div class="CodeBlockHeader">Code:</div> | ||
+ | <syntaxhighlight lang="sci"> | ||
+ | (method (changeState newState) | ||
+ | (switch (= state newState) | ||
+ | transition code... | ||
+ | ) | ||
+ | ) | ||
+ | </syntaxhighlight> | ||
+ | </blockquote> | ||
+ | </blockquote> | ||
+ | |||
+ | ====<br /> cue: ==== | ||
+ | <blockquote>Do a changeState: to the next state. Default is to invoke (self changeState:(+ state 1))</blockquote> | ||
+ | |||
+ | ====<br /> handleEvent: event ==== | ||
+ | <blockquote>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.</blockquote> | ||
+ | |||
+ | ====<br /> setScript: newScript whoCares register ==== | ||
+ | <blockquote>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.</blockquote> | ||
+ | </blockquote> | ||
| | ||
Line 76: | Line 125: | ||
<span style="float: left">[[Script Classes for Adventure Games/Inventory Class|< Previous: The Inventory Class]]</span> | <span style="float: left">[[Script Classes for Adventure Games/Inventory Class|< Previous: The Inventory Class]]</span> | ||
− | <span style="float: right">[[Script Classes for Adventure Games/Timer|Next: Timer >]]</span> | + | <span style="float: right">[[Script Classes for Adventure Games/Timer Class|Next: The Timer Class >]]</span> |
| |
Latest revision as of 22:35, 11 December 2015
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
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: | system.sc |
Inherits from: | Object |
Inherited by: | none |
Properties
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.
Methods
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.
- Notes
< Previous: The Inventory Class Next: The Timer Class >