[Newbies] Making a Wonderland Actor react to mouse clicks (was:
matthias.berth at googlemail.com
Tue Nov 7 18:20:18 UTC 2006
Hello Jeff :-)
interesting question, and I know the situation you're describing with
respect to getting the help you want.
OK, to the point of your problem: you want to turn a Wonderland actor (your
helicopter) in response to a mouse click. Here is a quick, concrete recipe,
tested in Squeak 3.8:
1) As you did, evaluate ("do it" ) this:
| wonder copter |
wonder := Wonderland new.
copter := wonder makeActorFrom: 'WonderlandObjects\Vehicles\Helicopter.mdl'.
2) Now _within_ the wonderland script window, evaluate this:
helicopter addResponse: [:event | helicopter turn: #left] to: #leftMouseUp
3) click on your helicopter and see what happens
Does that do what you want?
Now, how did I find out about this? (I'm not saying you should be able to
find this out for yourself, mind you. I'm just trying to help.)
1) Notice the Quick reference tab in the wonderland window
2) Somewhere down in that text you find
event types: keyPress, leftMouseDown, leftMouseUp, leftMouseClick,
rightMouseDown, rightMouseUp, rightMouseClick
addResponse: <block> to: <eventType>
removeResponse: <response> to: <eventType>
respondWith: <block> to: <eventType>
3) So it has to be something with addResponse. I still don't know how to use
the addResponse, however. So I open the method finder and type in
4) I find the method addResponse:to: in WonderlandActor
5) looking at the method source code in the browser, I don't get a idea of
how to use it. In most cases it's better to look at examples of the method
in use, so I click on "senders"
6) bummer: there are no senders of addResponse:to: !
7) in that same method category "event handling" there is another method
that looks similar: respondWith:to:, and that's also listed in the
wonderland quick reference
8) I find 3 senders of respondWith:to:, among them
"Set up our default reactions"
myReactions := Dictionary new.
self respondWith: [:event | self onLeftMouseDown: event] to:
self respondWith: [:event | self onLeftMouseUp: event] to: leftMouseUp.
9) So I interpret the method as this: There is a dictionary myReactions that
tells the actor what to do in response to an event. Event types are the
keys, blocks are the value of this dictionary. They initialize the reactions
to left mouse down and left mouse up with blocks that specify what to do on
these events. Now it makes sense: the block takes the event as an argument,
so you can ask the event object e.g. for the mouse coordinates
10) Now I have the basic format for the block, and an example on how to use
11) The last obstacle was to be able to "name" the helicopter inside the
wonderland, because it takes on its own name ("helicopter" instead of the
"copter" you used in the script).
I fully realize that this discovery process needs a lot of assumptions and
background knowledge about Squeak. I think this knowledge can be gradually
accumulated by playing with the system and trying to get small things done.
When you're stuck, you can always ask the mailing list.
I hope this helps, have fun.
On 11/7/06, Jeff <hombreviii at myway.com> wrote:
> Hello group!
> I'm hoping that this beginners list is a good place for a beginner to get
> answers to... well, beginner's questions. And so, with that in mind, I'll
> ask a few questions. But first, experience has taught me that I should be a
> little more clear in what I'm looking for as an answer. [...]
> 1. In a workspace, I've typed the following...
> wonder := Wonderland new.
> copter := wonder makeActorFrom: 'Objects\Vehicles\Helicopter.mdl'.
> copter turn:'left'.
> So far, everything works fine. The wonderland and helicopter are created,
> and I am able to send it messages to make it turn, move, etc. Now I'd like
> to make it move by using the arrow keys. How do I do that? [...]
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Beginners