Script Classes for Adventure Games/Object Class
Author: Jeff Stephenson
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.
|Inherited by||All classes|
nameThis 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.
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: whereFormat 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 objectCode:(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 writingUp to four arguments (besides the Code object ID) may be passed to perform:.Code:(foo perform: showMe)
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 writeCode:(list add: ((Actor new:) posn:100 100 view:5 setCycle: EndLoop myself: ) )
understands: selectorReturns TRUE if the object has a method corresponding to selector, FALSE otherwise.