alice-teacher switching which object is controlled by arrows

Don Slater dslater at andrew.cmu.edu
Wed Nov 23 13:13:41 EST 2011


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.a2w
Type: application/octet-stream
Size: 1137769 bytes
Desc: not available
Url : https://lists.andrew.cmu.edu/mailman/private/alice-teachers/attachments/20111123/225b6888/attachment-0001.obj 
-------------- next part --------------







On Nov 17, 2011, at 10:13 AM, Emily Higgins wrote:

> Hello -
> Thank you to the person that reminded me to put my topic in the subject line.  I have a student who is trying to make a scene in which the user can choose which object to control with arrow keys.  The objects, both fish, moves fins all the time, so he both needs to have the selected fish do its "swim" method and be controlled.  Then, if the user clicks on a different fish, that fish should do its "swim" method and be controlled by arrows. It seems like I should be able to have him use a parameter that is assigned upon being clicked and then switch with fish is swimming or being controlled.  
> 
> Thank you,
> Emily Higgins
> Boothbay Harbor, Maine
> _______________________________________________
> alice-teachers mailing list
> alice-teachers at lists.andrew.cmu.edu
> https://lists.andrew.cmu.edu/mailman/listinfo/alice-teachers



More information about the alice-teachers mailing list