Thanks Ron,There's some good info. in there. Unfortunately, scene doesn't have respondWith: to: method, but I might be able to find a workaround. One method I was trying to use in the past was to create a script from tiles, and have that script always ticking and just send the helicopter the command to move in response to the world's last keystroke. I couldn't get the script to find the helicopter at all, and have been having trouble with going from one workspace to another attempting to refer to the same thing, and also with the differences between tile scripts and workspace scripts, for some reason they don't act the same and I'm not sure why. Even when I tried creating a class MyWonderland with instance variables | wonder copter |, I couldn't figure out how to get a method to understand what 'copter' was and pass messages to it other than the one that created it. Also related, when I define jump as jumpup := wonder helicopter move:#up.I still don't know exactly how to make this method do this again. I've tried World jumpup. jumpup. wonder helicopter jumpup. but only jumpup loop. seems to work, and again only from the particular workspace I defined it in. I know all of this is related somehow. Anyone got a hint? --- On Wed 11/08, Ron Teitelbaum < Ron@USMedRec.com > wrote:From: Ron Teitelbaum [mailto: Ron@USMedRec.com]To: hombreviii@myway.com, beginners@lists.squeakfoundation.orgDate: Wed, 8 Nov 2006 11:07:48 -0500Subject: KeyPress On World of Squeak Wonderland (was: Disappointed)Hi Jeff, Welcome to the beginners list! I appreciate the fact that you aresticking with the problem. That in my opinion is the best way to learn. Ididn�t answer your question because I do not feel that I am an expert inWonderland. If the question was something like how can I map a key to sosome action that is pretty easy, IF that action is an isolated easily calledmethod. Something like: Utilities garbageCollectAndReport. This isa class method and there is no instance that needs to be sent to. If a key stroke needs to be captured and affecta running instance it is a bit more difficult to do but still very possible. Theissue here is that there is a complicated event loop that needs to be tappedinto but this would be very difficult to explain to someone with limited experience. The fact that you are using wonderland means that there is probably already ahook to do what you want so a complicated explanation of what I know willprobably only confuse the matter and make things more difficult for you. There are people on this list that havemuch more experience with Wonderland, but nobody that will answer your questionwithin hours. I would love to have Squeak be much more apleasant experience for you. My suggestion is that you start slower andwork on understanding basic concepts of Squeak. Do more tutorials; lookinto how some things work before trying to extend them. Also a comment, starting with theassumption that people are not going to help you is discouraging to people whomight. People are more likely to help people that work hard themselvesand will benefit from the help and will appreciate that help. I think youhave the work hard part down. You need to be a bit more appreciative ofthe effort and time that goes into helping you. Now to your question: Matthias was rightand he sent you to exactly the place you needed to go. I justloaded a 3.8 image and did the helicopter tutorial. I have to say it wasgreat fun! Wonderland is a very nice piece of code and I can see that itwould be fun to play with. The tutorial is fun but the concepts are noteasy and how the authors did what they did is very clever but also difficult especiallywhen you venture off the beaten path. You picked a hard place tostart! That by itself can be very frustrating. Here is your answer but the answer is notperfect. What I noticed is that the keys only have focus when the actoris under the mouse. There may be a way to make this work in the contextof a world but I couldn�t get it to work that way. The world doesnot appear to have a reactions collection, but there does seem to be a little hookin Scene that might have been intended to work that way. Again this is anadvanced concept. I also tried adding a reaction to the ground to make iteasier for this to work. The ground accepted the reaction but did not acton it. I added a reaction of [:event | self halt] but that did nothing somaybe background items like ground and sky don�t quite work or don�trespond to certain reactions the way other actors do. It makes sense thatWonderland might be written this way. If you added a right key press tomultiple objects how is it supposed to know which item the key press shouldcontrol. There could be a number of ways to fix this like adding an actorthat is a control stick or something, then placing the mouse over the controlstick would work the helicopter. (just a suggestion of where you might gofrom here) Ok so here is the code: helicopter addResponse: [:event | eventgetMorphicEvent keyString = '' ifTrue:[helicopter move: #left]. eventgetMorphicEvent keyString = '' ifTrue:[helicopter move: #right].] to: #keyPress I hope that helps, welcome to the list and Happy coding, Ron TeitelbaumPresident / Principal Software EngineerUS Medical Record SpecialistsRon@USMedRec.com face="Times New Roman">From:face=Tahoma>beginners-bounces@lists.squeakfoundation.org[mailto:beginners-bounces@lists.squeakfoundation.org] style='font-weight:bold'>On Behalf Of JeffSent: Wednesday, November 08, 200612:28 AMTo:beginners@lists.squeakfoundation.orgSubject: [Newbies] Disappointed I'm pretty disappointed with this list at the moment. My last post,"beginners questions" talked about how beginners often don't gettheir questions answered and pointed out that often when the experts see thatan answer, ANY answer, was given they then assume the question was answered, sothey don't offer anything more. Now I do appreciate Matthias's honest attemptto answer the question, so I don't want this to be misconstrued as an attack onhim. But he obviously misread it. And, well, once people saw that the questionof how to make a wonderland actor move in response to mouse clicks had beenanswered, I didn't get any more help. The question I asked was how to move awonderland actor with the arrow keys, and I need to do that without the actorhaving the focus. Unfortunately, since it's been taking so many hours for themessages I've tried to send to get posted on here, (I think I had screwed upjoining the list somehow, and redid it so hopefully that problem is solved), ittook me a full day to get my question asked and now another full day to explainthat the answer I got was to a different question. By the by, I've beenspending about 10 hours a day for 5 days now trying to solve this problem. It'sgetting quite frustrating for me and making me want to give up on squeak. border=0 width=23 height=23 id="_x0000_i1025"src="http://imgfarm.com/images/webmail/rt/img/img1017a1.gif%22%3E;
_______________________________________________ No banners. No pop-ups. No kidding. Make My Way your home on the Web - http://www.myway.com
Hi Jeff,
This is actually one of the things that I found interesting about wonderland. It's a bit too cleaver. In my block I would have expected to have
[:event | self move: #left] since the code is being stored on a helicopter but instead I needed to put in [:event | helicopter move: #left]. Now it seems that Wonderland is doing what it is you want but at the expense of making you believe this is some sort of magic.
The answer to your question is rather simple, but it will be confusing with what you have already seen.
The answer is: Object message. Every message is sent to an object, and objects can be either Classes or instances. But even this is a bit confusing since Classes are instances of a Class, but forget I mentioned that.
Now a Class can have instances. Like this: aGlass := Glass new.
This sets the temp variable aGlass to an instance of the Class Glass. It's relatively easy to find a class in Smalltalk since it does it for you automatically. If you had created the class Glass then select Glass and inspect_it will bring up the class definition. This is not true for instances. You are required to manage your own instances of a class. Normally we do this by storing instances in instance variables. This helps to form a relationship between objects.
So if I did this
Object subclass: Glass
instanceVariables: 'content'
Glass>>initialize
"initialize the instance of Glass"
content := OrderedCollection new.
Glass>>content
"return a collection of matter that represents contents of a glass"
^content
Object subclass: Matter
Matter subclass: Liquid
Liquid subclass: Water
Matter subclass: Solid
Solid subclass: Ice
Then I could make an Instance of Ice and put it in the Glass.
aGlass := Glass new.
aGlass content add: Ice new.
^aGlass
If I do this then I get back an instance of Glass with some ice in it. Now I could set some properties so that ice over time turns into water.
Notice something about this. If I go to another workspace and do
aGlass := Glass new.
I get a new glass, not the same one as before. Is it possible for me to go to another workspace and get the same glass back? Yes but this is not the way that we normally do things. If I add an id to glass this will make more sense.
aGlass := Glass new;
id: 'Glass 1';
yourself.
Now in another workspace I can do:
myGlass1 := Glass allInstnaces detect: [:a | a id = 'Glass 1'] ifNone: [Transcript show: 'you need glasses'].
So if this is not how we would normally do things what is? Well remember ice? We made an instance of Ice and it's still in the glass.
aGlass := Glass new.
aGlass content add: Ice new.
If we wanted to get this back in the same code we could use the aGlass temporary variable to retrieve it.
myContent := aGlass content at: 1 ifAbsent: [Transcript show: 'you still need glasses'. nil].
Now myContent has Ice in it.
(we would actually do something like this instead. But instead of talking about methods and browsers since we are still in a workspace, I'm trying to give you an example that will make sense:
aGlass := Glass new.
myIce := Ice new.
aGlass content add: myIce.
See now we don't have to retrieve it back since we already have a temp variable)
What is wonderland doing?
Well something very interesting, it is holding onto instances of Actor and naming them and replacing those names for you. So while it looks like you are just using the name, you are really using temporary variables. Cool huh?
How does all this help you? Well if you start wonderland in a workspace:
Wonderland new.
You can inspect this. (not do_it but inspect_it instead). You will get back an inspector which IS the wonderland instance you are looking for. You can now write any code you want to try out on the instance. w or your instance of Wonderland is now: self, so on your inspector you can do: self addActor: . or whatever. You can find your actors, browse code, do all kinds of cool stuff. You can not save this code. This is a way for you to get used to what's going on. It's a try it area. Look around, inspect more things, browse code that makes up these instances.
The key take away here is that instances are like children. They are not interchangeable. It's like children. You don't get the same one each time you make a new one. And you don't ask a question of just any child. You need to ask your daughter to clean up the backyard, and your son to do the dishes, or whatever.
Happy coding,
Ron Teitelbaum
President / Principal Software Engineer
US Medical Record Specialists
Ron@USMedRec.com
_____
From: beginners-bounces@lists.squeakfoundation.org [mailto:beginners-bounces@lists.squeakfoundation.org] On Behalf Of Jeff Sent: Wednesday, November 08, 2006 1:44 PM To: Ron@USMedRec.com; hombreviii@myway.com; beginners@lists.squeakfoundation.org Subject: [Newbies] RE: KeyPress On World of Squeak Wonderland (was:Disappointed)
Thanks Ron, There's some good info. in there. Unfortunately, scene doesn't have respondWith: to: method, but I might be able to find a workaround.
One method I was trying to use in the past was to create a script from tiles, and have that script always ticking and just send the helicopter the command to move in response to the world's last keystroke. I couldn't get the script to find the helicopter at all, and have been having trouble with going from one workspace to another attempting to refer to the same thing, and also with the differences between tile scripts and workspace scripts, for some reason they don't act the same and I'm not sure why. Even when I tried creating a class MyWonderland with instance variables | wonder copter |, I couldn't figure out how to get a method to understand what 'copter' was and pass messages to it other than the one that created it. Also related, when I define jump as jumpup := wonder helicopter move:#up.
I still don't know exactly how to make this method do this again. I've tried World jumpup. jumpup. wonder helicopter jumpup. but only jumpup loop. seems to work, and again only from the particular workspace I defined it in. I know all of this is related somehow. Anyone got a hint?
--- On Wed 11/08, Ron Teitelbaum < Ron@USMedRec.com > wrote:
From: Ron Teitelbaum [mailto: Ron@USMedRec.com] To: hombreviii@myway.com, beginners@lists.squeakfoundation.org Date: Wed, 8 Nov 2006 11:07:48 -0500 Subject: KeyPress On World of Squeak Wonderland (was: Disappointed)
Hi Jeff,
Welcome to the beginners list!
I appreciate the fact that you are sticking with the problem. That in my opinion is the best way to learn. I didnt answer your question because I do not feel that I am an expert in Wonderland. If the question was something like how can I map a key to so some action that is pretty easy, IF that action is an isolated easily called method. Something like: Utilities garbageCollectAndReport. This is a class method and there is no instance that needs to be sent to.
If a key stroke needs to be captured and affect a running instance it is a bit more difficult to do but still very possible. The issue here is that there is a complicated event loop that needs to be tapped into but this would be very difficult to explain to someone with limited experience. The fact that you are using wonderland means that there is probably already a hook to do what you want so a complicated explanation of what I know will probably only confuse the matter and make things more difficult for you.
There are people on this list that have much more experience with Wonderland, but nobody that will answer your question within hours.
I would love to have Squeak be much more a pleasant experience for you. My suggestion is that you start slower and work on understanding basic concepts of Squeak. Do more tutorials; look into how some things work before trying to extend them.
Also a comment, starting with the assumption that people are not going to help you is discouraging to people who might. People are more likely to help people that work hard themselves and will benefit from the help and will appreciate that help. I think you have the work hard part down. You need to be a bit more appreciative of the effort and time that goes into helping you.
Now to your question: Matthias was right and he sent you to exactly the place you needed to go. I just loaded a 3.8 image and did the helicopter tutorial. I have to say it was great fun! Wonderland is a very nice piece of code and I can see that it would be fun to play with. The tutorial is fun but the concepts are not easy and how the authors did what they did is very clever but also difficult especially when you venture off the beaten path. You picked a hard place to start! That by itself can be very frustrating.
Here is your answer but the answer is not perfect. What I noticed is that the keys only have focus when the actor is under the mouse. There may be a way to make this work in the context of a world but I couldnt get it to work that way. The world does not appear to have a reactions collection, but there does seem to be a little hook in Scene that might have been intended to work that way. Again this is an advanced concept. I also tried adding a reaction to the ground to make it easier for this to work. The ground accepted the reaction but did not act on it. I added a reaction of [:event | self halt] but that did nothing so maybe background items like ground and sky dont quite work or dont respond to certain reactions the way other actors do. It makes sense that Wonderland might be written this way. If you added a right key press to multiple objects how is it supposed to know which item the key press should control. There could be a number of ways to fix this like adding an actor that is a control stick or something, then placing the mouse over the control stick would work the helicopter. (just a suggestion of where you might go from here)
Ok so here is the code:
helicopter addResponse: [:event |
event getMorphicEvent keyString = ''
ifTrue: [helicopter move: #left].
event getMorphicEvent keyString = ''
ifTrue: [helicopter move: #right].
] to: #keyPress
I hope that helps, welcome to the list and
Happy coding,
Ron Teitelbaum
President / Principal Software Engineer
US Medical Record Specialists
Ron@USMedRec.com
face="Times New Roman">
_____
From:face=Tahoma> beginners-bounces@lists.squeakfoundation.org [mailto:beginners-bounces@lists.squeakfoundation.org] style='font-weight:bold'>On Behalf Of Jeff Sent: Wednesday, November 08, 2006 12:28 AM To: beginners@lists.squeakfoundation.org Subject: [Newbies] Disappointed
I'm pretty disappointed with this list at the moment. My last post, "beginners questions" talked about how beginners often don't get their questions answered and pointed out that often when the experts see that an answer, ANY answer, was given they then assume the question was answered, so they don't offer anything more. Now I do appreciate Matthias's honest attempt to answer the question, so I don't want this to be misconstrued as an attack on him. But he obviously misread it. And, well, once people saw that the question of how to make a wonderland actor move in response to mouse clicks had been answered, I didn't get any more help. The question I asked was how to move a wonderland actor with the arrow keys, and I need to do that without the actor having the focus. Unfortunately, since it's been taking so many hours for the messages I've tried to send to get posted on here, (I think I had screwed up joining the list somehow, and redid it so hopefully that problem is solved), it took me a full day to get my question asked and now another full day to explain that the answer I got was to a different question. By the by, I've been spending about 10 hours a day for 5 days now trying to solve this problem. It's getting quite frustrating for me and making me want to give up on squeak. border=0 width=23 height=23 id="_x0000_i1025" src="http://imgfarm.com/images/webmail/rt/img/img1017a1.gif%22%3E
_____
No banners. No pop-ups. No kidding. Make My Way your home on the Web - http://www.myway.com
beginners@lists.squeakfoundation.org