Script Classes for Adventure Games/Object Class

From SCI Wiki
Revision as of 03:10, 9 December 2015 by Andrew Branscom (talk | contribs)
Jump to navigationJump to 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 Object Class

Author: Jeff Stephenson

Date: 5 April 1988

 


The Object Class

Class Object is the super-class of the majority of the classes in Script. It defines the default behavior for these classes, ensuring that all objects will respond to a certain basic set of messages.

In file system.sc
Inherits from RootObj
Inherited by All classes


Properties:


name

This is a string representation of the name of the object or class. It is used by showSelf: to display the object. The compiler will use the symbol for an instance or class as its name unless name is explicitly set.


Methods


new

Returns the ID of a new instance of the class or object. This new instance has the same methods and property values as the parent. The property values can be changed, the methods cannot.


init

Initializes the object. If the object is to show up on the screen (Views, Props, Actors and Egos), this is the message which will make the it show itself. The default does nothing.


doit

Do your thing, whatever that may be. Sometimes this is sent when the object is selected, sometimes (as for Actors) it is sent for each animation cycle. The default does nothing.


dispose

Dispose of the object. If the object was created using new:, this reclaims the memory occupied by that object. In this case it is an error to refer to the object ID being disposed of once the dispose: message has been sent. Subclasses of Object should make sure that they dispose of any objects which they created before doing a (super dispose:).


showStr where

Format a string describing the object at the storage pointed to by where. The default string is the object name.


showSelf

Display this object in a meaningful way. This is primarily used for debugging, in order to find out which objects are present. The default is to print the string produced by showStr:.


perform: code [args...]

Execute code. Code must be an object of class Code with a doit: method whose first argument will refer to the object which is to perform the code. Thus, one way to implement showSelf: would be to create the Code object

Code:
(instance showMe of Code 
     (method (doit theObj) 
          (Print (theObj name?)) 
     ) 
)

You could then make the object foo show itself even if it did not have a showSelf: method by writing

Code:
(foo perform: showMe)

Up to four arguments (besides the Code object ID) may be passed to perform:.


myself

Returns the object ID of the receiver. This is useful as the last in a series of messages to an object to force the entire send to return the ID of the object. For example, if you wish to add a newly created and initialized Actor to a List, you could write

Code:
(list add:
     ((Actor new:)
          posn:100 100
          view:5
          setCycle: EndLoop
          myself:
     )
)


understands: selector

Returns TRUE if the object has a method corresponding to selector, FALSE otherwise.

 

Notes


 

Table of Contents

 

< Previous: The RootObj Class Next: The Collection Class >