Home
Project Folders
Teacher Resources
Student Resources
How Do I?
Literacy
MWForum
Site Map
Search
Our Team

MWForum Message [Date Index] [Threads] [Authors] [Attachments] [Subscribe]

[Thread Prev] <

To: Alan G Isaac <alan.isaac@xxxxxxxxx>
Subject: Re: respond to mouse *and* keys
From: Alain LCSI <alain@xxxxxxx>
Date: Tue, 18 May 2010 19:59:25 -0400

Hi Mr Isaac, Hello son,

There are many ways to achieve this, here's one:

Create two turtles: t1 and t2 in my example.

In the t1' s backpack, in the Rules tab, type
TRACKMOUSE 
in the OnClick field. Set it to FOREVER mode.

In the Procedures tab, create these two procedures:

TO TRACKMOUSE
TOWARDS "T2
IF KEY? [READKEYBOARD]
END

TO READKEYBOARD
MAKE "NUMBER ASCII READCHAR
IF :NUMBER = 29 [SETX XCOR + 5]
IF :NUMBER = 28 [SETX XCOR - 5]
IF :NUMBER = 30 [SETY YCOR + 5]
IF :NUMBER = 31 [SETY YCOR - 5]
END

In t2's backpack, on the Rules tab, type
SETPOS MOUSEPOS
in the OnClick field. Set it to FOREVER mode.

Now first click on t1. It should point towards t2.

Now click on t2, It should follow the mouse pointer.

Now hit the arrow keys.

Maybe you will need a button for STOPALL or SET "T1 "ONCLICK "FALSE and SET
"T2 "ONCLICK "FALSE 

Note: T2 does NOT have to be visible if it bugs you.

Good luck,

Alain Tougas
LCSI


Le 2010-05-17 à 15:08, Alan G Isaac a écrit :

> 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 way?)
> 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.
> 
> Suggestions?
> 
> Thanks,
> Alan Isaac
> 
> 
> 




  • Previous 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.


    © copyright 2001 - 2008