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

From SCI Wiki
Jump to navigationJump to search
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;

Revision as of 20:42, 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 >