[Squeakland] Problem with scope of objects

Scott Wallace scott.wallace at squeakland.org
Tue Nov 13 03:13:30 PST 2007


On Nov 13, 2007, at 12:24 AM, Luke Gorrie wrote:
>
> ...P.S. Any suggestions on more examples or documentation for  
> advancing users?

There is not much available about textual scripting.

However, here are a few notes that should help anyone who knows a  
little Smalltalk get started with textual scripting:

(1)  The "self" of a textual script is a *player* object, whose  
corresponding "morph" is found as its costume.  A (very annoying)  
complication is that if the morph has been rotated (i.e. its heading  
is not 0), the costume referred to in the player is actually not the  
original morph (e.g. a JoystickMorph, SketchMorph, or whatever it was  
that you started with) but rather a TransformationMorph which holds  
the rotation info and which is the "owner" of the actual morph.  If  
you have a script for some SketchMorph and you wish, in a textual  
script, to refer to the SketchMorph, and to be certain that the script  
still works if the SketchMorph is subsequently rotated, use the (very  
annoying) idiom "self costume renderedMorph" -- this will always get  
to the Morph you're most likely wishing to talk to in a textual script.

(2)  If in your script you wish to refer to the "World" morph, you can  
use the global name "ActiveWorld".

(3)  To refer to any "variable" belonging to the player, as seen in  
the "variables" section of its Viewer, use the special "getter" and  
"setter" idioms:  for example, to get a player's heading, send it  
"getHeading", and to *set* the player's heading to 5, for example,  
send it "setHeading: 5".   Similarly, for the variable "x" it would be  
"setX" and "getX", and so forth.

(4)  Keep a Transcript open when you're doing textual scripting, to  
see reports of "runtime errors", i.e., errors that arise in executing  
your textual scripts; otherwise these will be simply swallowed silently.

------

Here's a simple example of textual script, itself of no value except  
to show how you can enumerate and identify objects and interact with  
objects on the screen.  Set it to ticking and it will gradually nudge  
all objects (except flaps) to the right of the screen:

-------------- next part --------------
A non-text attachment was scrubbed...
Name: pastedGraphic.tiff
Type: image/tiff
Size: 173614 bytes
Desc: not available
Url : http://squeakland.org/pipermail/squeakland/attachments/20071113/8703fc4e/pastedGraphic-0001.tiff
-------------- next part --------------




------

Here's a less trivial example, which does something that is otherwise  
very difficult to do with tiles.

The Shark (a little star) has a "player-valued" variable called  
"nearestFish".  The shark's "findNearestFish" script is a textual  
script that first makes a list of all the non-sharks in the aquarium,  
then computes which of them is *nearest* to the shark, and, finally,  
places a reference to that nearest fish in the Shark's "nearestFish"  
variable, where it is subsequently used by the shark's "pursue" script.

As the simulation advances, you can see whom the Shark regards as its  
nearest fish by looking at the "Shark's nearestFish" watcher found  
below the aquarium.

The little triangular fish are all "siblings" running the same  
"meander" script.

The third and final script in the project is the shark's "pursue"  
script, which makes the shark move toward whichever fish he considers  
the nearest at the moment.

Here's a (low-res) picture of all the components of this example:

-------------- next part --------------
A non-text attachment was scrubbed...
Name: pastedGraphic.jpg
Type: image/jpeg
Size: 163308 bytes
Desc: not available
Url : http://squeakland.org/pipermail/squeakland/attachments/20071113/8703fc4e/pastedGraphic-0001.jpg
-------------- next part --------------




I also attach a copy of the actual project. which was created using  
the existing Squeakland system but will load and run equally well in  
an olpc etoys system.


Cheers,

   -- Scott

-------------- next part --------------
A non-text attachment was scrubbed...
Name: findNearestFish.001.pr
Type: application/octet-stream
Size: 78495 bytes
Desc: not available
Url : http://squeakland.org/pipermail/squeakland/attachments/20071113/8703fc4e/findNearestFish.001-0001.obj
-------------- next part --------------










More information about the Squeakland mailing list