[Squeakland] "add a parameter" script feature in etoys

Scott Wallace scott.wallace at squeakland.org
Tue Nov 6 16:55:10 PST 2007

On Nov 1, 2007, at 3:50 PM, Bill Kerr wrote:

> I can't assign a variable to the "add a parameter" feature available  
> through the scripts menu in etoys. The parameter type is displayed  
> and the type can be altered but it doesn't go green when I try to  
> replace it with a variable of the right type. I can drag off a tile  
> for the parameter type but that doesn't seem to help.

Hi, Bill,

I'm not sure I understand exactly what you're asking, but perhaps a  
few general words about script parameters, and a simple example, will  
be helpful...

The "Tile for the parameter type" that you can drag from the header of  
a Scriptor is actually a tile representing the parameter value  
itself.  You can drop such a tile at any type-appropriate place within  
the body of the script.  Thus, if the parameter type is "color", the  
tile will be labeled "Color", and can be dropped on any Color-type  
tile in the script, and if the parameter type is "number", the tile  
will be labeled "Number" and can be dropped on any Number-type tile in  
the script, etc.

I attach a small example which illustrates use of a script parameter.   
The script that has a parameter is called "wobble", and it takes a  
numeric-valued parameter.  Its role is to make the object turn by a  
random amount within the limit specified by the parameter.  The larger  
the value of the parameter, the wider will be the variance.  Notice  
that in the body of the script, there are two places where a "Number"  
tile, representing the value of the numeric parameter, is used.  Both  
of these "Number" tiles were obtained by dragging them from the  
"number" tile in parameter area in the header, then dropping them on  
numeric-valued tiles:

-------------- next part --------------
A non-text attachment was scrubbed...
Name: pastedGraphic.tiff
Type: image/tiff
Size: 157234 bytes
Desc: not available
Url : http://squeakland.org/pipermail/squeakland/attachments/20071106/28ee6f77/pastedGraphic-0002.tiff
-------------- next part --------------

A typical use of such a script can be seen in the two other scripts in  
the example, one called "wideWobble", which calls "wobble" with a  
parameter value of 70 (degrees), which makes for fairly wild random  
wobble, and the other called "narrowWobble", which calls "wobble" with  
a parameter value of 20 degrees, which makes for much less erratic  

Here's the script for "narrowWobble":

-------------- next part --------------
A non-text attachment was scrubbed...
Name: pastedGraphic.tiff
Type: image/tiff
Size: 232972 bytes
Desc: not available
Url : http://squeakland.org/pipermail/squeakland/attachments/20071106/28ee6f77/pastedGraphic-0003.tiff
-------------- next part --------------

You can experiment with the behavior of these two scripts by holding  
down the yellow "!" control for one or the other, or by first making  
one of them "ticking", then observing the effect, then stopping that  
script and making the other one tick, etc.  Or, for a combined effect  
(fwiw) make them both tick at the same time, perhaps at different  
ticking rates.

BTW:  we have successfully prototyped a much better UI for presenting  
parameters to the user; the new design allows the user to *name* the  
parameter, allows a *default value* for the parameter to be specified  
in the scriptor's header, and (because of now having a default value)  
also allows a script with a paremeter to be set "ticking".   But  
unfortunately we haven't had time yet to bring this into the  
mainstream etoys system.

> I'm trying to make a fractal tree in etoys but need two parameters.  
> Is it possible?

No, sorry, only one parameter is allowed per script in this version of  

The standard workaround for this is to pass the desired additional  
parameter info in a *variable* which you add to the object for just  
this purpose, and which you set in the caller, and which you "get" in  
script itself.  This requires extra bookkeeping by the person writing  
the script, and can cause problems in recursive-call situations, but  
otherwise in practice is quite workable.  And, since the data being  
passed reside in visible variables belonging to the object, their  
values can be conveniently observed in Viewers and Watchers, which can  
be quite a good debugging aid.


   -- Scott

-------------- next part --------------
A non-text attachment was scrubbed...
Name: paramExample-sw.001.pr
Type: application/octet-stream
Size: 55015 bytes
Desc: not available
Url : http://squeakland.org/pipermail/squeakland/attachments/20071106/28ee6f77/paramExample-sw.001-0001.obj
-------------- next part --------------

More information about the Squeakland mailing list