Methods

Message Sending


frame:MethodName(parameters)


To call a method, you send a message to the frame containing the method. Sending a message is straightforward:

result := aFrame:Max(a, b);
The above code sends the Max message to aFrame.

Sending a message requires a frame (sometimes called an object) and the name of a function, along with parameters, if any. Between the frame and the function name is a colon (:).

The distinction between a method and a message is simple:

As you'll see in Chapter 4, Inheritance in NewtonScript, it is quite common to have many methods with the same name. When you send a message, the method that actually executes depends on inheritance. For example, you may have a Display method in many of your application template frames. Just as you would expect, the Display method that executes depends on which frame you send the message to and the rules of inheritance.


Note:A common mistake NewtonScript programmers make is to type a . instead of a : when sending a message (frame.Message() instead of frame:Message()). We call this the off-by-one-pixel syntax error. Here is the chatty error you get:

//-- Error: "<input>", Line 1, syntax error--read '(', but wanted end-of-file, '&', ')', '*', '+', ',', '-', '.', '/', ':', ';', '<', '>', '[', ']', '}', SYMBOL, END, THEN, ELSE, ONEXCEPTION, TO, BY, UNTIL, DO, WITH, ASSIGN, AND, OR, LEQ, GEQ, EQL, NEQ, EXISTS, AMPERAMPER, DIV, MOD, LS

Just remember when you see this error to check for periods instead of colons in your messages.


self
Variable Lookup Rules
Effects of Variable Lookup Rules

An online version of Programming for the Newton using Macintosh, 2nd ed. ©1996, 1994, Julie McKeehan and Neil Rhodes.

Last modified: 1 DEC 1996