[Newbies] Re: Making a wonderland actor respond to keystrokes, not mouseclicks? (was: Beginners questions)

Jeff hombreviii at myway.com
Tue Nov 7 21:12:20 UTC 2006


 
I sent Matthias an email already thanking him for his assistance but I wanted to email the list too, so that people reading here wouldn't think that telling me how to make the copter turn when I click on it actually answered my question. What I'm really trying to do is make it reply to the arrow keys, and without needing to have the focus to do so, (and without the camera or any other wonderland piece requiring the focus either).Also, I'm wondering why when I run the following in a workspace...wonder := Wonderland new.copter := wonder makeActorFrom: 'Objects\Vehicles\helicopter.mdl'.I can make the copter turn from that workspace using...copter turn: #left.But if I open a different workspace and enter the same thing, it tells me that copter is an undefined object. Along the same lines, if I type...jump := wonder doInOrder: {copter move: #up. copter move: #down.}.the helicopter moves up and then down as expected. However, what exactly is "jump" now? I try executing 
just...jump.and nothing happens. I try...World jump.and get a PasteUpMorph doesNotUnderstand jump error. I tryjump new.and get SequentialAnimation(Object) does not understand new. Ok, so it's a sequential animation object, but how do I use it? It sounds like an object that actually is a method, but what object to send it to?Thanks again to Matthias and anyone else who tries to help me solve this. :)Jeff --- On Tue 11/07, Matthias Berth < matthias.berth at googlemail.com > wrote:From: Matthias Berth [mailto: matthias.berth at googlemail.com]To: hombreviii at myway.com, beginners at lists.squeakfoundation.orgDate: Tue, 7 Nov 2006 19:20:18 +0100Subject: Re: [Newbies] Making a Wonderland Actor react to mouse clicks (was: Beginners questions)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: #leftMouseUp3) click on your helicopter and see what happensDoes 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 window2) Somewhere down in that text you findAdding Reactions--------------------Useful constants:    event types: keyPress, leftMouseDown, leftMouseUp, leftMouseClick,            rightMouseDown, rightMouseUp, rightMouseClickaddResponse:  to: removeResponse:  to: respondWith:  to: 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 addResponse4) I find the method addResponse:to: in WonderlandActor5) 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 reference8) I find 3 senders of respondWith:to:, among them initializeDefaultReactions    "Set up our default reactions"    myReactions := Dictionary new.    self respondWith: [:event | self onLeftMouseDown: event] to: leftMouseDown.    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 coordinates10) Now I have the basic format for the block, and an example on how to use it11) 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.MatthiasOn 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? [...]

_______________________________________________
No banners. No pop-ups. No kidding.
Make My Way  your home on the Web - http://www.myway.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/beginners/attachments/20061107/ba5925b5/attachment-0001.htm


More information about the Beginners mailing list