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

Bert Freudenberg bert at freudenbergs.de
Wed Nov 8 12:44:09 UTC 2006


Also, in particular when posting over in the experts list (squeak- 
dev), take this document to heart:

	http://catb.org/esr/faqs/smart-questions.html

- Bert -

Am 08.11.2006 um 11:17 schrieb Roel Wuyts:

> Hello,
>
> I understand the situation from your point of view: you post a  
> question, get an answer which does not exactly solve your problem,  
> and get no more answers after that). It happened to me in the past  
> as well, on other mailinglists.
>
> I see two solutions to overcome this problem in the future (and  
> they are not orthogonal, both can and should be applied):
> * the 'experts' should try to detect this issue if they see the  
> problem occuring.
> * the person that sent the question should, when the problem  
> occurs, sent a new message with another subject where the original  
> question is asked again, probably slightly rephrased to not receive  
> the same answer twice ;-)
>
>
> What I personally do (as expert) is only replying to subjects for  
> which I feel that I can truly act as the expert. I then read the  
> whole thread, and if I find that I have another point of view or I  
> feel that I can add something to the responses, I do (this is the  
> detection of the issue on my part). Otherwise I say nothing (it  
> does not help to flood a newbie too much). I assume that other  
> experts do the same. This pattern implies that, after an answer has  
> been given by another expert, and I am happy with that answer, I  
> will not say anything. If another message with a similar subject  
> pops up, I will again read it, and might answer it.
>
> So, basically I am saying that you should keep posing your question  
> until you are truly satisfied with the answer ;-)
>
>
> On 07 Nov 2006, at 22:12, Jeff wrote:
>
>>
>> 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 try
>> jump 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.org
>> Date: Tue, 7 Nov 2006 19:20:18 +0100
>> Subject: 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:  
>> #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
>>
>>
>> Adding Reactions
>> --------------------
>>
>> Useful constants:
>> event types: keyPress, leftMouseDown, leftMouseUp, leftMouseClick,
>>
>> rightMouseDown, rightMouseUp, rightMouseClick
>>
>> addResponse: 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 addResponse
>>
>> 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
>>
>>
>>
>> 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 coordinates
>>
>> 10) Now I have the basic format for the block, and an example on  
>> how to use it
>>
>> 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.
>>
>> Matthias
>>
>>
>> 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? [...]
>>
>>
>>
>>
>>
>> No banners. No pop-ups. No kidding.
>> Make My Way your home on the Web - http://www.myway.com
>> _______________________________________________
>> Beginners mailing list
>> Beginners at lists.squeakfoundation.org
>> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>
> _______________________________________________
> Beginners mailing list
> Beginners at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/mailman/listinfo/beginners



More information about the Beginners mailing list