Difference between revisions of "Script Classes for Adventure Games/Object Class"

From SCI Wiki
Jump to navigationJump to search
 
Line 64: Line 64:
 
<blockquote>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.</blockquote>
 
<blockquote>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.</blockquote>
  
====<br /> init ====
+
====<br /> init: ====
 
<blockquote>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.</blockquote>
 
<blockquote>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.</blockquote>
  
====<br /> doit ====
+
====<br /> doit: ====
 
<blockquote>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.</blockquote>
 
<blockquote>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.</blockquote>
  
====<br /> dispose ====
+
====<br /> dispose: ====
 
<blockquote>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:).</blockquote>
 
<blockquote>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:).</blockquote>
  
====<br /> showStr where ====
+
====<br /> showStr: where ====
 
<blockquote>Format a string describing the object at the storage pointed to by where. The default string is the object name.</blockquote>
 
<blockquote>Format a string describing the object at the storage pointed to by where. The default string is the object name.</blockquote>
  
====<br /> showSelf ====
+
====<br /> showSelf: ====
 
<blockquote>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:.</blockquote>
 
<blockquote>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:.</blockquote>
  
Line 100: Line 100:
 
Up to four arguments (besides the Code object ID) may be passed to perform:.</blockquote>
 
Up to four arguments (besides the Code object ID) may be passed to perform:.</blockquote>
  
====<br /> myself ====
+
====<br /> myself: ====
 
<blockquote>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  
 
<blockquote>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  
  

Latest revision as of 20:55, 11 December 2015

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 >