Quote:
Originally Posted by gdev
I have assigned my students a problem where they need to use a shape to be the on off button. If you click the shape it changes from green to red or vice versa to indicate stop or go. The button is initally red, when clicked changes to green but when clicked again I get an error when changing it back to red. I have no idea what is going on. I attatched the file below. Please help.
|
Hello gdev,
The good news is that I don't see anything that is obviously wrong with your program.
The bad news is that I believe you have stressed the concurrent programming capability of Alice beyond its breaking point. The first revised program that I attached relieves some of that stress and runs successfully. However, it isn't very satisfying in terms of your objective.
Even in Java, which is the underlying language of Alice, where it is possible to write code that executes a great deal of control over what is going on, multithreaded or concurrent programming is one of the most difficult kinds of programming to do correctly. It is often much easier to get it wrong than it is to get it right. In addition, the failure modes are often much more obscure than the failure mode in your program.
(Often it is the customer who discovers the failure.) In fact, entire books have been written on how to correctly do concurrent programming in Java.
Since Alice is a language within a language, and Alice supports some degree of concurrent programming, it is no surprise to me that it is possible to write Alice programs that get crosswise with the underlying concurrent programming capabiliies of Java and fail.
Unfortunately, when that happens in Alice, you don't get much in the way of helpful diagnostic information. Finding and fixing the problem is pretty much a matter of continuing to eliminating things until the problem goes away. Of course, experience helps in the troubleshooting process, but it can still be very difficult. After some effort along that line, I discovered that eliminating the
doTogether block in your
while something is true event handler would eliminate whatever it is that is causing the problem. My rationale was to eliminate as much concurrent programming as I could in an attempt to eliminate the cause of the problem. Unfortunately, that also eliminated the overall effectiveness of your animation. It caused the cars to take turns, which is obviously not what you were after.
I believe that the second file that I attached below will do the job that you intended to do. It isn't as elegant as your original version that is based on the
while something is true event, but it is much safer.
Hope this helps.
Dick Baldwin