[etoys-dev] duplicates and siblings
sthomas1 at gosargon.com
Wed Feb 23 10:32:58 EST 2011
There is a chapter
in the manual that discusses siblings, thanks to Karl for adding this)
excerpts from that re-written below.
When you make a copy of an object any changes made to the copy or the
original only affect the object changed.
Siblings are related in that they share certain things in common, in
particular: scripts and variable definitions. So if you add a variable to
one sibling, all siblings will have their own instance of that variable with
the same name. The same name, but the values can be different. For example
if I add a variable called "speed" to one sibling, all siblings will have a
variable with that name. But I can have one sibling with speed=5 and another
with speed=10. Same variable name different values.
Also if I add a script to one sibling, all siblings will have the same
script (and same scripting tiles, if I change it in any sibling at anytime).
But although siblings share a script, each sibling has its own private
"status" for that script, i.e. remembers separately whether the script as
used by this instance is "normal", "paused,", or "ticking", or set to
trigger on mouse-up, etc.; and what the tick-rate is.
So why would you use siblings? Well besides teaching one of the most
fundamental concepts of object oriented programming, you could use siblings
in a game to make characters that have similar behaviors (aka scripts) but
different looks (you can change the looks by either re-drawing the sketch or
by setting the Sketch's graphic (if the object is a Sketch or image you
copied in) or changing its size and colors. You could also have ships in a
game that keep track of how many times they were hit (using a variable to
count the # of hits). That way you can program a basic ship once and make
multiple siblings. Then if you decide to change the behavior (ex: modify a
script, or add a new variable), you can change it once and all the siblings
Siblings could also be used to try to simulate or model real world behavior.
For example deer population or some other animal. You could create an
Object that simulates the behavior of a deer: searches for food, ages,
breeds (at a certain age), etc. and make sibling copies of that one object.
Then each Sibling (aka individual instance of the Class Deer which you have
defined) could age, search for food (and find it or not which could affect
its life expectancy), etc at its own rate. You could also create predators
and food that grows. Then run multiple simulations varying the amount of
food, starting number of dear, # of predators, etc.
If the "all instances" box is not checked in AllPlayers, you'll see the
scripts for only one player of each sibling group. This will give you
"control" over the scripts of only one of the players. If you want to be
able to "control" scripts for both of the siblings, make sure the "all
instances" checkbox is checked.
On Wed, Feb 23, 2011 at 9:36 AM, Rita Freudenberg <
rita at isg.cs.uni-magdeburg.de> wrote:
> I'm working on the Etoys reference manual right now, and on one place I
> want to describe the difference between sibling and duplicate. I hope
> someone here can help me. Here is what I wrote, is this correct? (the green
> double boxes refer to the green halo icon).
> The green double boxes in the top right duplicates the object. If you hold
> down the shift key you will create a sibling object. There is a difference
> between siblings and duplicates. At the moment of creation, it is the same,
> you will get a copy of the object and all it's scripts. But if you later
> change an existing script of the original object, the same script of the
> siblings will change automatically, too. The same script of the duplicates
> will stay the same as of the moment of the duplication.
> etoys-dev mailing list
> etoys-dev at squeakland.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the etoys-dev