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

From SCI Wiki
Jump to navigationJump to search
(Created page with "Official SCI Documentation<br /> <div align="center"> Chapter: 1 | Object Oriented Programming i...")
 
 
(3 intermediate revisions by the same user not shown)
Line 18: Line 18:
 
&nbsp;
 
&nbsp;
  
xxxxxxx body xxxxxxxx
+
==<br /> 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:
 +
 
 +
===<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>
 +
<div class="CodeBlockHeader">Code:</div>
 +
<syntaxhighlight lang="sci">
 +
(ego x:23) or (ego x: 23)
 +
</syntaxhighlight>
 +
</blockquote>
 +
 
 +
sets the x property of ego to 23.
 +
</blockquote>
 +
 
 +
===<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>
 +
<div class="CodeBlockHeader">Code:</div>
 +
<syntaxhighlight lang="sci">
 +
(ego x?)
 +
</syntaxhighlight>
 +
</blockquote>
 +
 
 +
will return the value of the x property of ego.
 +
</blockquote>
 +
 
 +
===<br /> Invoking a method ===
 +
<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 (':'):
 +
 
 +
<blockquote>
 +
<div class="CodeBlockHeader">Code:</div>
 +
<syntaxhighlight lang="sci">
 +
(ego moveTo: x y) or (ego moveTo:x y)
 +
</syntaxhighlight>
 +
</blockquote>
 +
 
 +
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:
 +
 
 +
<blockquote>
 +
<div class="CodeBlockHeader">Code:</div>
 +
<syntaxhighlight lang="sci">
 +
(ego
 +
    x:50
 +
    y:50
 +
    setMotion: MoveTo 100 100
 +
    setCycle: Reverse self
 +
)
 +
</syntaxhighlight>
 +
</blockquote>
 +
 
 +
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 >