alice-teacher switching which object is controlled by arrows
David Fenton
fenton at fdn.uq.edu.au
Wed Nov 23 17:38:34 EST 2011
Interesting solution Don,
I refined your J key event to use a simple call directly to the world.activeObject and it works perfectly.
When the key is pressed, we *know* which is the active object so we don't need to check if it is the 'hare' or the 'tortoise' - the event becomes more generic. Hope this is useful.
See attached screenshot. I used the 'space' key.
Cheers
David Fenton Ô¿Ô
Brisbane Australia
-----Original Message-----
From: alice-teachers-bounces+fenton=fdn.uq.edu.au at lists.andrew.cmu.edu [mailto:alice-teachers-bounces+fenton=fdn.uq.edu.au at lists.andrew.cmu.edu] On Behalf Of Don Slater
Sent: Thursday, 24 November 2011 4:14 AM
To: Alice educators
Subject: Re: alice-teacher switching which object is controlled by arrows
Now for the second part of my thoughts on this.
How can we create events that work for multiple objects, and distinguish between the different objects.
A simple version of the problem.
See the attached world: "mouseclickChoice.a2w"
I have created a world level object variable and named it "activeObject".
I have also created a world level method named "setActiveObject" which has an object parameter "objectClickedOn". I created a "when the mouse is clicked anything do" event. This event calls "setActiveObject". When prompted for the parameter, in the drop-down menu, I selected the "expressions" option, which gave me access to the "object under mousecursor".
The "setActiveObject" method has an if statement
if "objectClickedOn" == "hare"
set the activeObject method to "hare"
else if "objectClickedOn" == "tortoise"
set the activeObject method to "tortoise"
else
// do nothing
Then I created a "when 'F' key is pressed" event, with an if statement
if "activeObject" == "hare"
// hare does its thing
else
// tortoise does its thing
When you "Play" this world, when you click on the hare, and press F the hare moves up and down, when you click on the tortoise, and press F the tortoise moves up and down. If you click on any other object in the world, such as the ground, the last object selected will respond to the F key.
---- Note ---
How to compare objects.
In the if statement, when you want to compare object variables to objects in the world ("objectClickOn" == "hare") for example.
1) drag the if control into the editor.
2) drag the object variable or parameter so as to replace "true" in the if statement
3) you will be given several options from the drop down menu. Select the appropriate operation and complete the expression
Please let me know if you have any questions.
All the best,
Don Slater
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mouseclickChoice.png
Type: image/png
Size: 27972 bytes
Desc: mouseclickChoice.png
Url : https://lists.andrew.cmu.edu/mailman/private/alice-teachers/attachments/20111124/4aa7c0b2/attachment.png
More information about the alice-teachers
mailing list