Getting Started with E-Toys / User Scripting
Last updated at 12:23 pm UTC on 17 January 2006
User Scripting or "E-Toys" is a powerful and simple visual scripting system built into Squeak. Scripts can be created using drag and drop for any Morphic object.
There are two ways to create a new Morph: it can be drawn or created directly from code. Lets start with a drawing.
Drawing a Morph
- Left click on the screen to open the World Menu
- Choose "New Morph..."
- Choose "Make new drawing"
- Click anywhere on the screen with the "Painting" icon to create a painting area. The painting area will be a white translucent area with painting tools to the right.
- Create a painting and choose "Keep" from the paint tools area.
- Choose "Toss" to delete the picture if you want.
An even easier way to create a painting area is to click on the "Widgets" flap (bottom of screen) and drag out the painting icon.
When you are painting your morph, keep in mind that you have the entire painting canvas to make your morph on. Whatever is on the canvas will become your morph even if there are painted areas that don't touch!!
If your morph is not quite the way you want it after you clicked "Keep", you can edit it with the "repaint" option. To edit your morph:
- Alt-left click the morph to get the halo.
- Click the red menu icon in the halo (top left beside the "X")
- Choose the "painting" option at the bottom of the menu, then choose "repaint".
You will now have an active paint tool to edit your morph with.
You may have also noticed several other options in the "painting" menu such as "rotational center". With "rotational center" you can set the center of rotation for your morph. The interesting part about this is that the "center" does not have to be on the area that you painted. It can be placed anywhere in the painting area !!!
Now that you have created the Morph object, we will need to open a viewer to start scripting it.
Opening a Viewer for your Morph Object
- Alt-left click your morph to get the halo.
- Click on the blue "eyeball" icon (left side) to open a viewer.
The viewer will now appear on the right side of the screen. On the top left corner of the viewer you will notice a small square with a picture of your morph in it. This is the Viewer tab. Clicking this tab will hide and unhide the viewer.
The top of the viewer has three icons and the name of the Morph. The top, left most icon, the "O", will close the viewer. The other "O"s will close their respective category. the next icon over that looks like miniature lines of text, will add another category pane to the viewer. The menu icon will display a menu with several options. The most important of which is "add a new instance variable". This menu option is the fastest way to add a new variable to your morph script. We will add an instance variable later on. Finally, the name of the morph object is displayed. The name of the Object can be changed simply by clicking the name twice to place a cursor and then typing the new name. You can confirm this by right clicking the object to get its halo. At the botoom of the halo will be the object's new name. You will also notice every line in the viewer now reflects the name change.
Missing File (/squeak/uploads/viewer.jpg)
The first pane from the top is the "search" pane. It allows you to find any word in any of the category panes whether the pane is visible or not (more on that later). Let's give it a try.
Two new lines will appear which are from the Geometry category.
- Type "theta", without the quotes, into the search pane.
The remainder of the viewer consists of category panes. These panes can be closed by clicking it's "O" icon. It's category can be changed by clicking the up/down triangles or by clicking the category name and choosing a new one from the list. The remainder of the category panes are filled with commands.
Let's create a new script and start using some commands !
There are two ways to create a new script.
- Click the menu icon at the top of the viewer
- Choose "add new script". Your cursor will change to a green "new script" icon.
- To cancel the script creation just click anywhere on the desktop but not in the viewer.
Click and drag any command from any category to the desktop. Commands need to be dragged from the middle (eg. click on "make sound" or "forward by") to pick them up.
A "scripts" category pane will appear in the viewer and your script window will appear on the desktop.
More to come !!!