[Squeakland] 1 script -> N objs

Bert Freudenberg bert at impara.de
Wed Feb 23 06:09:33 PST 2005


Am 23.02.2005 um 03:54 schrieb Randy Heiland:

> Thanks for both your replies.  I failed to communicate exactly what I 
> wanted
> to do.  I see that both your techniques do indeed impart a given 
> script to
> another object.  However, what I'm looking for is a simple way to 
> execute a
> single script and have it act on N (sibling) objects (where N can be 
> large).
> Basically, I want to reproduce the behavior of the StarSqueak objects 
> (e.g.
> slimemold).

Not sure if this helps in your specific case, but often changing the 
point of view solves such problems quite easily.

For example, we were doing a PacMan game in etoys. In this game you 
steer a figure (PacMan) through a maze, eating all peas that are 
scattered along the way.

In each step, the PacMan needs to test if it touches a pea and then eat 
(remove) that pea. Normally you would try to write a script for the 
PacMan object to do this. However, in etoys it's much easier to 
implement if you reverse the logic - let each pea decide if it is 
eaten. We made a script for the pea that looks if this pea is touching 
the PacMan and if so, remove it.

Of course, all peas share this behaviour as they are siblings. 
Essentially, iterating over N objects in a script is the same as 
calling that script in N objects ...

- Bert -



More information about the Squeakland mailing list