Difference between revisions of "Object Oriented Programming in Script/Sending Messages"

From SCI Wiki
Jump to navigationJump to search
 
(One intermediate revision by the same user not shown)
Line 22: Line 22:
 
The syntax for sending a message to an object is identical to that for a procedure call.  The object name (or an expression which evaluates to an object ID) is followed by the message selector and any parameters, all enclosed in parentheses.  There are three different kinds of messages which can be sent to objects:
 
The syntax for sending a message to an object is identical to that for a procedure call.  The object name (or an expression which evaluates to an object ID) is followed by the message selector and any parameters, all enclosed in parentheses.  There are three different kinds of messages which can be sent to objects:
  
===<br /> Setting a property: ===
+
===<br /> Setting a property ===
 
<blockquote>A property of an object can be set by sending a message whose message selector is the name of the property followed by a colon (':') followed by the new value of the property:
 
<blockquote>A property of an object can be set by sending a message whose message selector is the name of the property followed by a colon (':') followed by the new value of the property:
  
Line 35: Line 35:
 
</blockquote>
 
</blockquote>
  
===<br /> Requesting the value of a property: ===
+
===<br /> Requesting the value of a property ===
 
<blockquote>The value of a property can be obtained by sending a message with no parameters whose message selector is the name of the property followed by a question mark ('?'):
 
<blockquote>The value of a property can be obtained by sending a message with no parameters whose message selector is the name of the property followed by a question mark ('?'):
  
Line 48: Line 48:
 
</blockquote>
 
</blockquote>
  
===<br /> Invoking a method: ===
+
===<br /> Invoking a method ===
 
<blockquote>
 
<blockquote>
 
A method of an object can be invoked by sending a message with any number of parameters whose message selector is the name of the method followed by a colon (':'):
 
A method of an object can be invoked by sending a message with any number of parameters whose message selector is the name of the method followed by a colon (':'):
Line 77: Line 77:
  
 
will position ego at coordinates (50, 50), start him moving to coordinates (100, 100), and set him to cycle in reverse cel order.  When multiple messages are sent to an object, the messager in the kernel sends them one at a time in left to right order.  In multiple message sends, all parameters are evaluated before the messages are sent.
 
will position ego at coordinates (50, 50), start him moving to coordinates (100, 100), and set him to cycle in reverse cel order.  When multiple messages are sent to an object, the messager in the kernel sends them one at a time in left to right order.  In multiple message sends, all parameters are evaluated before the messages are sent.
 +
</blockquote>
  
 
&nbsp;
 
&nbsp;

Latest revision as of 22:24, 5 December 2015

Official SCI Documentation

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


Sending Messages

Author: Jeff Stephenson

Date: 4 April 1988

 


Sending Messages

The syntax for sending a message to an object is identical to that for a procedure call. The object name (or an expression which evaluates to an object ID) is followed by the message selector and any parameters, all enclosed in parentheses. There are three different kinds of messages which can be sent to objects:


Setting a property

A property of an object can be set by sending a message whose message selector is the name of the property followed by a colon (':') followed by the new value of the property:

Code:
(ego x:23) or (ego x: 23)

sets the x property of ego to 23.


Requesting the value of a property

The value of a property can be obtained by sending a message with no parameters whose message selector is the name of the property followed by a question mark ('?'):

Code:
(ego x?)

will return the value of the x property of ego.


Invoking a method

A method of an object can be invoked by sending a message with any number of parameters whose message selector is the name of the method followed by a colon (':'):

Code:
(ego moveTo: x y) or (ego moveTo:x y)

tells ego to move to coordinates x and y by invoking the moveTo method of ego.


Any number of messages can be sent in one fell swoop:

Code:
(ego
     x:50
     y:50
     setMotion: MoveTo 100 100
     setCycle: Reverse self
)

will position ego at coordinates (50, 50), start him moving to coordinates (100, 100), and set him to cycle in reverse cel order. When multiple messages are sent to an object, the messager in the kernel sends them one at a time in left to right order. In multiple message sends, all parameters are evaluated before the messages are sent.

 

Notes


 

Table of Contents

 

< Previous: Objects Next: An Extended Example >