alice-teacher Event Listeners and Handle Active Command in Alice 3.1

Don Slater dslater at andrew.cmu.edu
Mon Oct 6 12:57:33 EDT 2014


Attached find screenshots for both an Alice 2 and an Alice 3 implementation (you did not mention which version you were working with.)

In Alice 2, you would create the isClickedOn variable by selecting the “world” object, the “properties” tab in the “details” panel and click on the “create variable” button. The “A2_<sccreenshots>” show the rest of the implementation, including the event.

In Alice 3, if would create a “isClickedOn" property in the Cow class (see Screen shot “A3_CowProperty”. This will automatically create the procedural method “setIsClickedOn” method and the ‘getIsClickedOn” functional method for you in Alice, which you will then see used in the EventListener (“A3_Event”) and the “appear” method of the Cow class (“A3_CowAppear”). The score would be a property of the Scene class, to be used by some score object (not implemented) (“A3_firstMethod”)

You could also create the isClickedOn variable for the Cow object in Alice 2.

I hope that this helps.

Later,
Don Slater

 





On Oct 6, 2014, at 8:34 AM, Emily Higgins <erphiggins at gmail.com> wrote:

> Don -
> Could you send a screenshot of how you would program what you did the algorithm for Whack-A-Mole?  I can't figure out where to put the isClickedOn variable.
> 
> Refresher - the question was how to control when an event listener is activated, and the response was this:
> So my code might look something like
> 
> 	Scene variable / property -> boolean isClickedOn = false;
> 
> 	Event definition - mouseClickListener
> 
> 		if (mouse clicks on target) and (not isClickedOn)
> 			add 1 to score
> 			isClickedOn = true
> 
> 	target move method
> 		hide target
> 		if (isClickedOn)
> 			isClickedOn = false
> 		move target
> 		showTarget
> 
> 
> 	myFirstMethod
> 		while (score < targetScore) or (time runs out)
> 			target move
> 		game over
>  
> 
> Thank you
> Emily Higgins
> 
> On Wed, Oct 1, 2014 at 12:51 PM, Don Slater <dslater at andrew.cmu.edu> wrote:
> See below...
> 
> On Oct 1, 2014, at 9:39 AM, Emily Higgins <erphiggins at gmail.com> wrote:
> 
>> Dear All-
>>  I have two questions. 
>> 1)  What does the Handle Active command do in Alice 3.1?
> 
> I assume you mean the HandleActiveChanged method of the Scene class. This is a method that will facilitate the creation of multiple scenes in Alice 3 when it is implemented. If you look at what it does right now (see attached screen shot), you will see that it essentially builds the current (and only possible) Scene, readying it for execution. It is not a method you or your students need to use at this time.
> 
>> 2) How can you set up a program so that an object is only affected by an event listener for part of the program?  For example, a student wants to have the program user move a box but only at a certain point of the program.  I can't figure out how to limit when an event listener is active.  
> 
> The student should create a boolean variable for the Scene class that is initially set to false as the program runs, and at the time when the student wants the event to become active, he sets the value of the variable to true. He would reset it to false when he no longer wants to listen for the event.
> 
> Then the event would be guarded by an if statement, that performs the event action when the variable is true.
> 
> For example, i have a type of “Whack-A-Mole” game in which the player is supposed to click on the target object when it appears, but you only one to add one point at most for each appearance of the target.
> 
> So my code might look something like
> 
> 	Scene variable / property -> boolean isClickedOn = false;
> 
> 	Event definition - mouseClickListener
> 
> 		if (mouse clicks on target) and (not isClickedOn)
> 			add 1 to score
> 			isClickedOn = true
> 
> 	target move method
> 		hide target
> 		if (isClickedOn)
> 			isClickedOn = false
> 		move target
> 		showTarget
> 
> 
> 	myFirstMethod
> 		while (score < targetScore) or (time runs out)
> 			target move
> 		game over
> 
> Let me know if you have any other questions.
> 
> All the best,
> 
> 
> <handleActive.png>
> 
> Don Slater
> Alice Team
> Carnegie Mellon University
> 5000 Forbes Avenue
> Pittsburgh, PA 15213
> 
> Email: don at alice.org
> 
> I have learned this at least by my experiment: that if one advances confidently in the direction of his dreams, and endeavors to live the life he has imagined, he will meet with a success unexpected in common hours.
> --- Henry David Thoreau
> 
> The true object of all human life is play. -- G.K. Chesterton
>> 
>> Thank you,
>> Emily Higgins
>> Boothbay Region High School
>> Boothbay Harbor, Maine
>> _______________________________________________
>> alice-teachers mailing list
>> alice-teachers at lists.andrew.cmu.edu
>> https://lists.andrew.cmu.edu/mailman/listinfo/alice-teachers
> 
> 
> _______________________________________________
> alice-teachers mailing list
> alice-teachers at lists.andrew.cmu.edu
> https://lists.andrew.cmu.edu/mailman/listinfo/alice-teachers
> 
> 
> _______________________________________________
> alice-teachers mailing list
> alice-teachers at lists.andrew.cmu.edu
> https://lists.andrew.cmu.edu/mailman/listinfo/alice-teachers

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.andrew.cmu.edu/pipermail/alice-teachers/attachments/20141006/b95f699f/attachment-0001.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: A2_isClickedOn.png
Type: image/png
Size: 297331 bytes
Desc: not available
Url : http://lists.andrew.cmu.edu/pipermail/alice-teachers/attachments/20141006/b95f699f/attachment-0006.png 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: A2_isClickedOn_2.png
Type: image/png
Size: 298945 bytes
Desc: not available
Url : http://lists.andrew.cmu.edu/pipermail/alice-teachers/attachments/20141006/b95f699f/attachment-0007.png 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: A3_CowAppear.png
Type: image/png
Size: 68182 bytes
Desc: not available
Url : http://lists.andrew.cmu.edu/pipermail/alice-teachers/attachments/20141006/b95f699f/attachment-0008.png 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: A3_CowProperty.png
Type: image/png
Size: 166216 bytes
Desc: not available
Url : http://lists.andrew.cmu.edu/pipermail/alice-teachers/attachments/20141006/b95f699f/attachment-0009.png 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: A3_Event.png
Type: image/png
Size: 84464 bytes
Desc: not available
Url : http://lists.andrew.cmu.edu/pipermail/alice-teachers/attachments/20141006/b95f699f/attachment-0010.png 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: A3_firstMethod.png
Type: image/png
Size: 32265 bytes
Desc: not available
Url : http://lists.andrew.cmu.edu/pipermail/alice-teachers/attachments/20141006/b95f699f/attachment-0011.png 


More information about the alice-teachers mailing list