[Thread Prev] [Thread Next]
I love the ideas you have used (the hidden turtle). Consider something
t1, ht setinstruction [forever [setpos mousepos]]
t2, setinstruction [forever [towards "t1]]
t3, setinstruction [forever [make "key ascii readchar
if :key = 38 [t2, glide 200 2]]]
[mailto:mwforum-bounces@xxxxxxxxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Alan
Sent: Monday, May 17, 2010 12:08 PM
Subject: respond to mouse *and* keys
My son is learning Microworlds.
I'm trying to help him when he gets stuck.
He is young (11) and I am not a Microworlds user,
so our questions may be pretty naive.
In a certain setting, he wants a turtle (say, t1) to do two things:
- keep pointing toward the mouse-pointer location, and
- move in response to the arrow keys
We can do each thing individually.
To point to the mouse-pointer position we did the following:
we created an invisible turtle that always moves to the mouse position,
and we use `towards` to point t1 towards that turtle. (Is this a good
Let's call the procedure `face`.
We then tried making a `move` procedure that
- checks for a key press (using key?)
- if an arrow key is pressed, moves
- calls face (which is *not* recursive)
- calls move
The turtle t1 does keep turning to face the mouse pointer.
Bit the key presses do not seem to be detected.
If we comment out the call to `face`, the key presses are detected
and movement is as desired.
Previous by thread:
respond to mouse *and* keys
Next by thread:
Re: respond to mouse *and* keys
To save an attachment to your computer, PC users should right-click (Mac users, click and hold the mouse button) on the link and then choose 'save target as' from the pop-up menu. A window will then pop up in which you can choose a location for the file.