
NewtonScript Examples
counter := {
lastCount: 0,
Next: func()
begin
return lastCount := lastCount + 1;
end,
}
#4408F31 {lastCount: 0,
next: <function, 0 arg(s) #4408D6D>}
We test the code by sending the frame the Next message repeatedly:
counter:Next(); #4 1 counter:Next(); #8 2 counter:Next(); #C 3Now, let's print out the counter object to verify that the value of the
lastCount slot has indeed changed:
counter
#4408F31 {lastCount: 3,
next: <function, 0 arg(s) #4408D6D>}
Resetting the counter back to 0 is no harder than making its value zero:
counter.lastCount := 0; #0 0Now, when you send the
Next message, you get brand new counts:
counter:Next(); #4 1 counter:Next(); #8 2 counter:Next(); #C 3
An online version of Programming for the Newton using Macintosh, 2nd ed. ©1996, 1994, Julie McKeehan and Neil Rhodes.
Last modified: 1 DEC 1996