Morphic name access trouble

Scott Wallace Scott.Wallace at disney.com
Sun Oct 24 22:56:08 UTC 1999


Stefan,

> In fact, my problem is general; I have it every time I want to make a
> morph and do something with it from within a script (for instance
> giving it a position).

The orange halo handle on the left side of an object's halo lets you "tear off a reference" to it.  You can drop such a reference tile anywhere in any script that an object reference is appropriate.

Another way -- the preferred way -- is to bring up a viewer for the object you want to do something to, drag out a phrase from that viewer, and drop it into any script.  Thus, if you want to manipulate Fred's x-coordinate, get Fred's viewer, drag from the purple-and-blue left-pointing arrow, and you'll get a phrase of the form "Fred's x  <- 28".  You can drop this into a script belonging to Fred or to any other object, and then proceed to manipulate it to do your bidding.


> In this particular case, I had made an eye that followed the mouse
> cursor movements (just like Xeyes for unix). But I accidentally
> deleted the Morph. However, the programming that I have done for the
> moving behaviour was still present as a Player class. So I wanted to
> make a new SketchMorph, and make it use the old Player class by
> scripting "Sketch2 player: Player2." or similar. But then I got the
> error that Sketch2 was unknown as an instance variable.

The guy you accidentally deleted should still be available in the Trash; open up the trash can (Squeak flap) and pull it out.  Unless of course you've set up your preferences such that deleted objects are not moved the trash.

However, if you can't get it that way, you can still get it.  This is because every Player instance points to its associated Morph in its costume slot.

So in your particular case, just evaluate the following in a workspace:

  self currentHand attachMorph: Player2 someInstance costume

and magically your lost morph, complete with its scripts, will there be in your hand.


> Another thing that strikes me as odd is that when I duplicate a morph
> (for example to get two eyes), I don't get a new instance, but an
> entire new class.

Well, there are cases where you'd want the one and cases where you'd want the other.  The "duplicate" comand does indeed duplicate the player class.  To get another instance of the same player class, use "make another instance of me", which you'll find in the halo menu.

   -- Scott





More information about the Squeak-dev mailing list