Etoys wizardry - enhancements in 3.8 and 3.9
Last updated at 11:41 am UTC on 28 August 2010
The new Squeakland release and the recent 3.8 and 3.9 images contain a number of enhancements to Etoys.
This page will try to document a few.
Extending the Etoys vocabularies
Stefan Matthias Aust also asked on the squeak-dev list:
Another interesting question we got on the list (by a very motivated teacher):
How to extend eToys. The teacher would like to build an eToy based environment for teaching math to older kids, and he would like to provide some pre-defined tiles.
I think this view of Etoys as a framework for building curriculums is quite interesting, but there is no documentation about how to do "Etoy Metaprogramming".
And Ned Konz replied some more:
It is easy to add vocabulary items to Morph classes, and probably not as easy to extend (say) Number operations.
For instance, I don't know how you'd add unary Number operators like sin and cos.
To extend the vocabulary of a Morph, you can just add methods whose names begin with additionsToVocabularyCategory to the class side (look for such methods to get an idea of how this works).
For each item, you typically need a method in Player and the corresponding method(s) in your Morph class.
The methods will be called on the Player, and the Player typically asks its costume (a Morph) for values or sends it commands.
For example, here is
"Answer viewer additions for the 'layout' category"
(slot clipSubmorphs 'Whether or not to clip my submorphs' Boolean readWrite
Player getClipSubmorphs Player setClipSubmorphs:)
So this adds the 'clipSubmorphs' slot to the 'layout' vocabulary category.
That slot (a pseudo-variable) is read/write, and is implemented by the methods #getClipSubmorphs and #setClipSubmorphs in Player.
Those methods just call back to the morph that is the Player's costume:
"Getter for costume's clipSubmorphs"
^ costume renderedMorph clipSubmorphs
The other kind of thing you can add (besides the pseudo-variable 'slot' type) is the 'command' type, as in:
"Answer viewer additions for the 'miscellaneous' category"
(command doMenuItem: 'do the menu item' Menu)
(command show 'make the object visible')
These don't have an associated return value, but they can have a single typed parameter.