Object Oriented Programming in Script/Objects

From SCI Wiki
Jump to: navigation, search

Official SCI Documentation

Chapter: 1 | 2 | 3 | 4 | 5 | 6 | Index


Objects

Author: Jeff Stephenson

Date: 4 April 1988

 

Objects are specific instances of a class, and are defined using the instance statement:

Code:
(instance anObject of aClass
     (properties
          aProperty: value
          ...
     )
 
     (method (aMethod [p1 p2 ...] [&tmp t1 t2 ...])
          code
     )
     ...
 
     [(procedure ...)]
)

This defines an Object as an instance of class aClass. The properties and method statements are optional and are used to over-ride the default values and methods inherited from aClass.

The ID of an object or a class is what tells the sci kernel where to send messages. The object ID is obtained by simply writing the object's name wherever an expression is valid -- it can be assigned to a variable or passed as a parameter to a procedure. Thus, if we define egoObj as an instance of class Ego,

Code:
(instance egoObj of Ego)

we can assign the ID of egoObj to the global variable ego:

Code:
(global   ego       0) 
(= ego egoObj)

Once this has been done, the following two expressions are equivalent:

Code:
(ego x?)
(egoObj x?)

To find the distance from the object ego to the object wolf, we can pass the wolf's ID as an argument to ego's distanceTo: method:

Code:
(ego distanceTo: wolf)

Any unknown symbol encountered in a compilation is assumed to be the ID of some object which is to be defined later in the source file. If no object with the symbol as its name is encountered by the end of the file, an error will be raised.

 

Notes


 

Table of Contents

 

< Previous: Classes Next: Sending Messages >