Object Oriented Programming in Script/Objects: Difference between revisions

From Sierra Wiki
Jump to navigationJump to search
No edit summary
 
m (1 revision imported)
 
(No difference)

Latest revision as of 00:11, 3 June 2024

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:

<syntaxhighlight lang="sci"> (instance anObject of aClass (properties aProperty: value ... )

(method (aMethod [p1 p2 ...] [&tmp t1 t2 ...]) code ) ...

[(procedure ...)] )</syntaxhighlight>

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:

<syntaxhighlight lang="sci"> (instance egoObj of Ego) </syntaxhighlight>

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

Code:

<syntaxhighlight lang="sci"> (global ego 0) (= ego egoObj) </syntaxhighlight>

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

Code:

<syntaxhighlight lang="sci"> (ego x?) (egoObj x?) </syntaxhighlight>

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:

<syntaxhighlight lang="sci"> (ego distanceTo: wolf) </syntaxhighlight>

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 >