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

Don Slater dslater at andrew.cmu.edu
Wed Oct 1 12:51:11 EDT 2014


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,




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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.andrew.cmu.edu/pipermail/alice-teachers/attachments/20141001/5874d9a6/attachment-0001.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: handleActive.png
Type: image/png
Size: 200741 bytes
Desc: not available
Url : http://lists.andrew.cmu.edu/pipermail/alice-teachers/attachments/20141001/5874d9a6/attachment-0001.png 


More information about the alice-teachers mailing list