alice-teacher Alice Array Elements calling Methods

Donald Slater djslater107 at mac.com
Mon May 6 11:04:46 EDT 2019


Terri,
You are correct that eventListeners and arrays that have their values changed are tricky. In other words, if you create a MouseClickOnObject listener, and in details add the setOfVisuals argument with an array, that listener is “locked into" the array that is created at runtime, and updating the array has no effect on the listener. That is because the listener is in its own thread, and in Alice has no way of tracking changes made to the array in other threads (such as myFirstMethod), as the array will not really know if the event has been triggered before or after the array update in the other thread (a synchronization problem).

However, I found that if instead of using the setOfVisuals argument, I placed a for…each or each in… together control structure in the mouseClickOnObject listener and looped through the array to find the object that had been clicked on, if the array had been updated in any way, that updated version of the array is traversed, and the appropriate objects will respond.

I have attached a world, mouseClickWithArrays.a3p.

I have built an array of Bipeds, two mouseClickOnObjectListeners (one one is enabled at the moment), and code in myFirstMethod which adds and removes Bipeds from the array, after a couple of delay statements.

In the first listener, I am using the setOfVisuals argument, and even though the code in myFirstMethod is rearranging the array, this first listener works only with the original array initialization.

Disable the first listener and enable the second listener. This listener will traverse the current state of the array each time the event is fired, and when the array changes, the objects respond appropriately. (I could still have synchronization problems with this implementation To deal with this, you would have to create a state variable of some sort the listener looks at to determine if the state of the array has changed).

Let me know if you have any other questions.

All the best,
Don Slater

Alice Project



> On May 6, 2019, at 10:04 AM, Kelly, Terri <kellyt at bishopireton.org> wrote:
> 
> Awesome.
> 
> I hadn't thought of using the array of whole numbers, and truthfully, my high school students are definitely not ready for that kind of abstraction (well, a few are ... maybe I will show them, because I think that is a neat way to do it).
> 
> The unfortunate thing about trying to set it up randomly like this, is that the event listeners do not work ...
> 
> If I setup event listeners with the rowA, etc ... then the only type they fire is when the one car that I initialize them to collides with the markers ... 
> 
> If I run initialize event listeners from myFirstMethod ... they work ... BUT ... that causes all of the event listeners to be created twice ... which means that there are duplicate keyPressed events ... so, every time I press a key, the code is executed twice even if they are set to ignore/fire on keypree ...
> 
> Which also affects allowing the user to choose the variable that you want to use the objectMover for ... if you want the user to choose who they are moving around ... you have to write your own arrowkeypress listeners, as the objectMover gets set up before the world starts and even if you put a variable in there ... it only fires for the specific value at the start of the world.
> 
> Terri
> Computer Science
> Bishop Ireton
> 
> 
> On Mon, May 6, 2019 at 8:36 AM Donald Slater <djslater107 at mac.com <mailto:djslater107 at mac.com>> wrote:
> Terri,
> It is the craziest thing and I believe that you have found a bug.
> 
> It turns out that if I use the array “allCars”, the program will recognize and execute the drive procedure.
> 
> You have set up these supplemental arrays of Automobiles to keep track of the different rows of cars. You initialize these arrays with the black car, and then in setup successfully populate these arrays with random sets of cars, replacing the black car with different automobiles from the scene.
> 
> The setup works as you would expect If you print these row arrays, you see the different cars.
> 
> The bug seems to occur in that for some reason, even though these are arrays of automobiles, in the linking of the random car to the array, Alice loses track of the fact that there are methods associated with that object (in this case, drive), and simply ignores the call to that method. There may be a type problem here in that Alice uses SThing somehow in the reassignment of an object to an array of objects, but that is only speculation on my part, and the dev team may have more to say about this.
> 
> Another workaround, you have already found one, would be that your row arrays could be arrays of WholeNumbers, storing random indices from allCars rather than the car object. Then you could use the allCars array with the index values from these row arrays to call drive.
> 
> I have attached your original world (I have added a couple of statements to help me with debugging), plus a test world I built to help me check my hypothesis, for the dev team to look at. I will be interested to see if they have any other thoughts.
> 
> Thank you, and all the best,
> Don Slater
> 
> Alice Project
> 
> 
> 
>> On May 5, 2019, at 10:21 PM, Kelly, Terri <kellyt at bishopireton.org <mailto:kellyt at bishopireton.org>> wrote:
>> 
>> Don,
>> 
>> I tried to recreate it in a simple world and ... it worked.  So... there must be something in this crazy world.
>> 
>> There is a second problem that I would appreciate you taking a minute to look at.
>> 
>> So - the first problem is the calling of a class method from an item in an array ... the method I am trying to call is an automobile method named drive.  I am calling it from the scene level method moveRow, which is called from myFirstMethod after setup is done. Setup appears to work properly and I have put in several say statements to narrow down the problem.
>> 
>> The second issue is the event listener, collision... when I run this world, it takes FOREVER to return from running, unless I comment out the event listener.  The event listener worked great when there was just a small array of automobiles (5 in number), but when I added the other 15 ... it just almost seems to hang when returning from running...  It doesn't actually hang - it just takes forever to come back.
>> 
>> I recreated the entire world (everything) in a new Alice world and ... created 4 collision event listeners each with an array of just 4 items and ... the delay in ending execution occurred again.  
>> 
>> Thanks,
>> 
>> Terri KElly
>> Computer Science
>> Bishop Ireton
>> 
>> 
>> On Sun, May 5, 2019 at 6:00 PM Donald Slater <dslater at andrew.cmu.edu <mailto:dslater at andrew.cmu.edu>> wrote:
>> Terri,
>> Would you mind sending a copy of your program? I am trying to recreate the problem based on your description, but I do not think I am getting it right, as everything seems to be working for me… I must be missing something…
>> 
>> Also, I am using the latest download of Alice available on alice.org <http://alice.org/> (3.5). We added set and get indexed value into procedure and function list for all array properties, but I do not think that is related to your issue. But if you are using an older version of Alice you might try it.
>> 
>> Looking forward to hearing from you.
>> 
>> All the best,
>> Don Slater
>> 
>> Alice Project
>> 
>>> On May 4, 2019, at 4:27 PM, Kelly, Terri <kellyt at bishopireton.org <mailto:kellyt at bishopireton.org>> wrote:
>>> 
>>> I have a world which is not behaving like I am expecting it to.
>>> 
>>> I have an array of automobiles called rowA[]
>>> I have a method created for automobiles called go
>>> In go, the first thing I have this do is say it's Sthing (this say "" + SThing this)
>>> 
>>> If I call go with blueTruck, it works fine, the truck says blueTruck and then moves forward
>>> 
>>> blueTruck.go()
>>> 
>>> If I call go with rowA[0].go ... Alice hangs, 
>>> 
>>> So, from the test method I have
>>> 
>>> blueTruck.go()
>>> rowA[0] = blueTruck
>>> rowA[0].say "" + Sthing rowA[0]
>>> rowA[0].go
>>> 
>>> Is there any reason why I should not be able to call a class level method from an array that is of that type class?  
>>> 
>>> Terri Kelly
>>> Computer Science
>>> Bishop Ireton High School
>>> Alexandria, VA
>>> 
>>> The information contained in this communication may be subject to legal confidentiality protection or privilege. It is intended solely for use by the intended recipient and others authorized to receive it. If you have received this communication in error, please notify the sender and delete it immediately. You are hereby notified that any disclosure, copying, distribution or taking action in reliance of the contents of this information is strictly prohibited and may be unlawful.  The school accepts no liability whatsoever for any damage, loss, or expense arising from any misuse of this e-mail and/or from the accessing of any files attached to this e-mail._______________________________________________
>>> alice-teachers mailing list
>>> alice-teachers at lists.andrew.cmu.edu <mailto:alice-teachers at lists.andrew.cmu.edu>
>>> To change settings or unsubscribe visit:
>>> https://lists.andrew.cmu.edu/mailman/listinfo/alice-teachers <https://lists.andrew.cmu.edu/mailman/listinfo/alice-teachers>
>> _______________________________________________
>> alice-teachers mailing list
>> alice-teachers at lists.andrew.cmu.edu <mailto:alice-teachers at lists.andrew.cmu.edu>
>> To change settings or unsubscribe visit:
>> https://lists.andrew.cmu.edu/mailman/listinfo/alice-teachers <https://lists.andrew.cmu.edu/mailman/listinfo/alice-teachers>
>> The information contained in this communication may be subject to legal confidentiality protection or privilege. It is intended solely for use by the intended recipient and others authorized to receive it. If you have received this communication in error, please notify the sender and delete it immediately. You are hereby notified that any disclosure, copying, distribution or taking action in reliance of the contents of this information is strictly prohibited and may be unlawful.  The school accepts no liability whatsoever for any damage, loss, or expense arising from any misuse of this e-mail and/or from the accessing of any files attached to this e-mail.<Frogger.a3p>
> 
> 
> The information contained in this communication may be subject to legal confidentiality protection or privilege. It is intended solely for use by the intended recipient and others authorized to receive it. If you have received this communication in error, please notify the sender and delete it immediately. You are hereby notified that any disclosure, copying, distribution or taking action in reliance of the contents of this information is strictly prohibited and may be unlawful.  The school accepts no liability whatsoever for any damage, loss, or expense arising from any misuse of this e-mail and/or from the accessing of any files attached to this e-mail.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.andrew.cmu.edu/pipermail/alice-teachers/attachments/20190506/a210df53/attachment-0002.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mouseClickWithArrays.a3p
Type: application/octet-stream
Size: 52484 bytes
Desc: not available
URL: <http://lists.andrew.cmu.edu/pipermail/alice-teachers/attachments/20190506/a210df53/attachment-0001.obj>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.andrew.cmu.edu/pipermail/alice-teachers/attachments/20190506/a210df53/attachment-0003.html>


More information about the alice-teachers mailing list