alice-teacher Queue-up events

Don Slater dslater at andrew.cmu.edu
Fri Feb 18 12:27:39 EST 2011


Sorry, let me attach the world this time ;-(

---

-------------- next part --------------
A non-text attachment was scrubbed...
Name: eventQueue.a2w
Type: application/octet-stream
Size: 1772628 bytes
Desc: not available
Url : https://lists.andrew.cmu.edu/mailman/private/alice-teachers/attachments/20110218/9abce9c0/attachment-0001.obj 
-------------- next part --------------


See the attached example world which uses an event queue instead of a boolean flag. 

I have created a list of objects called events in World properties.

I have a World eventsHandler method which adds each object clicked on to the list.

I have a "while object is true event" that continues to fire as long as the list is not empty, calling the World processNextEvent method.

processNextEvent gets the next available object from the list, and then, depending on the object, calls the method I want the method to perform.

What I am unhappy about is the length of time it seems to take Alice to do the list processing. This may be an artifact of the way I wrote the code, or it may be just the way Alice handles lists.

Let me know if you have any questions.

All the best,
Don Slater



On Feb 18, 2011, at 9:29 AM, EILEEN PELUSO wrote:

> James,
> Could we see a sample of that?  I tried that with 3 monkeys (attached) and it works if I click on one and then a second, but if I click on all three, the (I'm assuming) threading in Alice's underlying Java code outwits me.  Multiple clicks on the monkeys result in them jumping in unison.
> Thanks!
> Eileen
> 
> Eileen Peluso, PhD
> Lycoming College
> Mathematical Sciences Department
> Williamsport, PA  17701
> 
>>>> On 2/18/2011 at 9:18 AM, in message <5DCE27CD-CD44-4875-B444-BB05890DA002 at benedictine.edu>, James Vanderhyde <jvanderhyde at benedictine.edu> wrote:
> 
> An easier solution to prevent the cup from activating before the blender finishes is to add a boolean variable "busy" to the scientist. In each event handler, check the variable to see if it's false. If false, set it to true and do the action. Then reset to false after the action. That way no actions can take place simultaneously. I showed many students how to do this in their Alice projects this year.
> 
> James
> --
> Dr. James Vanderhyde
> Math and Computer Science
> Benedictine College
> jvanderhyde at benedictine.edu
> http://vanderhyde.us/~james/pro/
> 
> 
> 
> On Feb 17, 2011, at 5:19 PM, Michael Bauer wrote:
> 
>> Suppose you create a world which uses multiple event handling, is there a way to queue-up user triggers of an event instead of having it start immediately?  For example, the Mad Scientist exercise in the textbook.  When the user clicks on an item (eg., the blender) and then clicks another item (eg., the cup) before the blender animation finishes, the cup animation starts immediately while the blender is still animated.  Is there a way to queue up the subsequent event triggers so that the cup in the above example doesn't start until the blender finishes even if the cup is clicked before the blender finishes?
>> Thanks,
>> Mike Bauer
>> University of Hawaii - Leeward Community College.
>> 
>> Hope to see many of you in Dallas next month.
>> _______________________________________________
>> 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
> <Three monkeys.a2w>_______________________________________________
> 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