Problem with scope of objects

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem with scope of objects

Christian Bode
Hi,

I am german cs student getting more and more amazed about squeak.
Tonight I began to play around a bit and wanted to do that amazing
"draw and steer your car" thing :)

I used this tutorial to get started:
http://www.dmu.com/squeak/sq0.html

Well, unfortunately i could not figure out this simple thing in 3 hours.
My problem is, after having added the car "Speedy" to the world, I cannot
reference to it from any other script. If I add a steerwheel to the
world, and
want attach a script to it, squeak is not able to resolve that
reference. It will
tell me that "Speedy" is undefined and ask me if I would like to declare
it global or create it.
I had this problem with all kinds of things; text fields, button etc. I
could
not manage to get the "Hello World", from the tutorial running
(http://www.dmu.com/squeak/sq1.html).

Did I get something wrong ? So before I loose interest I rather ask. I am
puzzled because I did it exactly the way described in the tutorial.

Thank you a lot!
Frederick (That´s a nick, if you wonder :))

_______________________________________________
Squeakland mailing list
[hidden email]
http://squeakland.org/mailman/listinfo/squeakland
Reply | Threaded
Open this post in threaded view
|

Re: Problem with scope of objects

Scott Wallace
Hello Christian,

I think that perhaps the "tutorial" you were looking at might not be  
the best way to get started with etoys.

First of all, to get a classic "Hello World" built in a Squeak  
project, there's no need to open a Viewer, nor to create or run a  
script.  If you want a project which, when loaded, displays the text  
"Hello World" (this is the classic definition of a "Hello World"  
program, I believe,) you can simply obtain a fresh "text" object from  
the supplies flap, then click to select the word "text" and then type  
to replace its contents with the words "Hello World".  If desired,  
resize the text object using the yellow resize handle.  Then save the  
project, and you're done.  This is not a programming task, but rather  
simply a get-to-know-the-environment task.

If for some reason you're intent on using a tile script to set the  
contents of the Text object, rather than simply directly editing the  
contents as described above, you can indeed pursue the approach  
suggested in that tutorial.  However, the tutorial's instruction that  
you click the checkbox in the Scriptor's header to change it from tile  
mode to textual mode seems to be what's leading you astray here.  
There's no reason to go to "textual mode" -- the task at hand is  
easily accomplished staying in tile mode, by simply text-editing the  
word "Text" to the right of the arrow in the script into the wording  
"Hello World":






Finally, I would guess that the problems you're having with object-
reference are because you are trying to refer to other objects by  
typing their names into textual code in textual scripts.  You should  
really stick to tiles, particularly until you've mastered the basics  
of tile scripting!  In the case of the classic drive-a-car demo, when  
you want "Car turn by 5" in a script to become "Car turn by Wheel's  
heading", you open Wheel's Viewer, grab "Wheel's heading" tiles from  
the Viewer, and drop them on the "5".

Also, you can use the orange "tile" handle in the halo of an object to  
"tear off a tile" that refers to that object.  Drop that tile onto any  
reference tile anywhere in any script and it will replace that tile.

What you were trying to do was probably to type a textual script in  
which you guessed at what the internal name used to refer to a  
particular object might be -- but this is not a reliable approach,  
since there is no restriction made on the format of external object  
names, nor any requirement of uniqueness, with the result that Squeak  
internally uses a regime of "internal names" which are syntactically  
acceptable and unique, and there is no guarantee of correlation  
between visible names and internal names.

So the bottom line is:  use tile scripts rather than textual scripts.  
Use drag-and-drop, rather than typing.  All of the introductory etoys  
materials that I'm aware of (other than the tutorial you ran across)  
operate strictly with tiles.  Textual scripting provides a great  
"escape" which opens up the entire universe of Smalltalk programming  
to the advancing user, but textual scripting certainly should play no  
role in "Hello World", nor in "Drive a Car", nor in any other  
introductory projects.


If this does not properly address your concerns, please ask further!


Cheers,

   -- Scott



On Nov 12, 2007, at 8:50 PM, Christian Bode wrote:

> Hi,
>
> I am german cs student getting more and more amazed about squeak.
> Tonight I began to play around a bit and wanted to do that amazing
> "draw and steer your car" thing :)
>
> I used this tutorial to get started:
> http://www.dmu.com/squeak/sq0.html
>
> Well, unfortunately i could not figure out this simple thing in 3  
> hours.
> My problem is, after having added the car "Speedy" to the world, I  
> cannot
> reference to it from any other script. If I add a steerwheel to the  
> world, and
> want attach a script to it, squeak is not able to resolve that  
> reference. It will
> tell me that "Speedy" is undefined and ask me if I would like to  
> declare
> it global or create it.
> I had this problem with all kinds of things; text fields, button  
> etc. I could
> not manage to get the "Hello World", from the tutorial running
> (http://www.dmu.com/squeak/sq1.html).
>
> Did I get something wrong ? So before I loose interest I rather ask.  
> I am
> puzzled because I did it exactly the way described in the tutorial.
>
> Thank you a lot!
> Frederick (That´s a nick, if you wonder :))
>
> _______________________________________________
> Squeakland mailing list
> [hidden email]
> http://squeakland.org/mailman/listinfo/squeakland

_______________________________________________
Squeakland mailing list
[hidden email]
http://squeakland.org/mailman/listinfo/squeakland

pastedGraphic.tiff (57K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Problem with scope of objects

Luke Gorrie-3
On 13/11/2007, Scott Wallace <[hidden email]> wrote:
> Textual scripting provides a great "escape" which opens up the entire universe of
> Smalltalk programming to the advancing user

Wow!!

I hadn't caught on to adding little snippets of Smalltalk code into
textual scripts on Players. I've been hacking
Morph>>additionsToViewerCategoryAsObject every time I need a new
one-off primitive and telling everybody here that it's the way it's
done. :-)

Thanks for the tip!
-Luke

P.S. Any suggestions on more examples or documentation for advancing users?

_______________________________________________
Squeakland mailing list
[hidden email]
http://squeakland.org/mailman/listinfo/squeakland
Reply | Threaded
Open this post in threaded view
|

Re: Problem with scope of objects

Bert Freudenberg

On Nov 13, 2007, at 9:24 , Luke Gorrie wrote:

> On 13/11/2007, Scott Wallace <[hidden email]> wrote:
>> Textual scripting provides a great "escape" which opens up the  
>> entire universe of
>> Smalltalk programming to the advancing user
>
> Wow!!
>
> I hadn't caught on to adding little snippets of Smalltalk code into
> textual scripts on Players. I've been hacking
> Morph>>additionsToViewerCategoryAsObject every time I need a new
> one-off primitive and telling everybody here that it's the way it's
> done. :-)

Ugh. Those would require a new image or filing in code - the textual  
scripts become part of the project.

> Thanks for the tip!
> -Luke
>
> P.S. Any suggestions on more examples or documentation for  
> advancing users?

I wish ... can't think of any.

- Bert -



_______________________________________________
Squeakland mailing list
[hidden email]
http://squeakland.org/mailman/listinfo/squeakland
Reply | Threaded
Open this post in threaded view
|

Re: Problem with scope of objects

Luke Gorrie-3
On 13/11/2007, Bert Freudenberg <[hidden email]> wrote:
> Ugh. Those would require a new image or filing in code - the textual
> scripts become part of the project.

Indeed. Currently we're customizing the image by loading a Monticello
repository worth of code. Previously we had a lot of media (sound,
images, etc) living in a custom image but that's moved into the
project files now. Later we'll want to be a bit clever about on-disk
sharing of common bitmaps, soundclips, etc and I don't know how yet
(I'm sniffing around objectForDataStream: and comeFullyUpOnReload: as
possible hooks - sounds fruitful?)

> I wish ... can't think of any.

I think that we need to get into the same room as an Etoys guru as
soon as we can. My experience is that Etoys skills such as we have so
far are very fast and easy to pass on face-to-face. I suppose that
webcasts are a great hope for scaling this up :-)

_______________________________________________
Squeakland mailing list
[hidden email]
http://squeakland.org/mailman/listinfo/squeakland
Reply | Threaded
Open this post in threaded view
|

Re: Problem with scope of objects

Bill Kerr
In reply to this post by Luke Gorrie-3
On Nov 13, 2007 7:24 PM, Luke Gorrie <[hidden email]> wrote:
P.S. Any suggestions on more examples or documentation for advancing users?


the search for quality etoys resources is frustrating

These materials might help ->
Author: Kathleen Harness

http://www.squeakcmi.org/resources.php?subpage=notebook

Paper copy of the SqueakCMI Notebook (15 MB)
http://www.squeakcmi.org/files/SqueakCMI%20Notebook.doc


more advanced ->

markus gaelli
http://www.emergent.de/etoys.html

http://www.iam.unibe.ch/~scg/Archive/Papers/Gael06aC5.pdf
idioms for composing games with etoys

--
Bill Kerr
http://billkerr2.blogspot.com/


_______________________________________________
Squeakland mailing list
[hidden email]
http://squeakland.org/mailman/listinfo/squeakland
Reply | Threaded
Open this post in threaded view
|

Re: Problem with scope of objects

Offray Vladimir Luna Cárdenas
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Bill,


Thanks a lot for this links, I was needing something like this for my
university students in the introductory part of a course. And by the
way, thanks a lot for your blog, I enjoy a lot reading it.

Cheers,

Offray

Bill Kerr wrote:

> On Nov 13, 2007 7:24 PM, Luke Gorrie <[hidden email]> wrote:
>
>> P.S. Any suggestions on more examples or documentation for advancing
>> users?
>
>
>
> the search for quality etoys resources is frustrating
>
> These materials might help ->
> Author: Kathleen Harness
> http://www.squeakcmi.org/resources.php?subpage=notebookPaper copy of the
> SqueakCMI Notebook (15 MB)
> http://www.squeakcmi.org/files/SqueakCMI%20Notebook.doc
>
>
> more advanced ->
>
> markus gaelli
> http://www.emergent.de/etoys.html
>
> http://www.iam.unibe.ch/~scg/Archive/Papers/Gael06aC5.pdf
> idioms for composing games with etoys
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Squeakland mailing list
> [hidden email]
> http://squeakland.org/mailman/listinfo/squeakland

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.1 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHOFPDpzl8tTvDAE8RAiPUAJ4//Rx0CR4EcG+hmeZhqByXRgVtTACgp67T
HV4kW4OGl4rGyBkySKUAJrU=
=yVIA
-----END PGP SIGNATURE-----

_______________________________________________
Squeakland mailing list
[hidden email]
http://squeakland.org/mailman/listinfo/squeakland
Reply | Threaded
Open this post in threaded view
|

Re: Problem with scope of objects

Scott Wallace
In reply to this post by Luke Gorrie-3
On Nov 13, 2007, at 12:24 AM, Luke Gorrie wrote:
>
> ...P.S. Any suggestions on more examples or documentation for  
> advancing users?

There is not much available about textual scripting.

However, here are a few notes that should help anyone who knows a  
little Smalltalk get started with textual scripting:

(1)  The "self" of a textual script is a *player* object, whose  
corresponding "morph" is found as its costume.  A (very annoying)  
complication is that if the morph has been rotated (i.e. its heading  
is not 0), the costume referred to in the player is actually not the  
original morph (e.g. a JoystickMorph, SketchMorph, or whatever it was  
that you started with) but rather a TransformationMorph which holds  
the rotation info and which is the "owner" of the actual morph.  If  
you have a script for some SketchMorph and you wish, in a textual  
script, to refer to the SketchMorph, and to be certain that the script  
still works if the SketchMorph is subsequently rotated, use the (very  
annoying) idiom "self costume renderedMorph" -- this will always get  
to the Morph you're most likely wishing to talk to in a textual script.

(2)  If in your script you wish to refer to the "World" morph, you can  
use the global name "ActiveWorld".

(3)  To refer to any "variable" belonging to the player, as seen in  
the "variables" section of its Viewer, use the special "getter" and  
"setter" idioms:  for example, to get a player's heading, send it  
"getHeading", and to *set* the player's heading to 5, for example,  
send it "setHeading: 5".   Similarly, for the variable "x" it would be  
"setX" and "getX", and so forth.

(4)  Keep a Transcript open when you're doing textual scripting, to  
see reports of "runtime errors", i.e., errors that arise in executing  
your textual scripts; otherwise these will be simply swallowed silently.

------

Here's a simple example of textual script, itself of no value except  
to show how you can enumerate and identify objects and interact with  
objects on the screen.  Set it to ticking and it will gradually nudge  
all objects (except flaps) to the right of the screen:






------

Here's a less trivial example, which does something that is otherwise  
very difficult to do with tiles.

The Shark (a little star) has a "player-valued" variable called  
"nearestFish".  The shark's "findNearestFish" script is a textual  
script that first makes a list of all the non-sharks in the aquarium,  
then computes which of them is *nearest* to the shark, and, finally,  
places a reference to that nearest fish in the Shark's "nearestFish"  
variable, where it is subsequently used by the shark's "pursue" script.

As the simulation advances, you can see whom the Shark regards as its  
nearest fish by looking at the "Shark's nearestFish" watcher found  
below the aquarium.

The little triangular fish are all "siblings" running the same  
"meander" script.

The third and final script in the project is the shark's "pursue"  
script, which makes the shark move toward whichever fish he considers  
the nearest at the moment.

Here's a (low-res) picture of all the components of this example:






I also attach a copy of the actual project. which was created using  
the existing Squeakland system but will load and run equally well in  
an olpc etoys system.


Cheers,

   -- Scott











_______________________________________________
Squeakland mailing list
[hidden email]
http://squeakland.org/mailman/listinfo/squeakland

pastedGraphic.tiff (232K) Download Attachment
pastedGraphic.jpg (218K) Download Attachment
findNearestFish.001.pr (104K) Download Attachment