Thread: Assignment 4
View Single Post
Old
Forumuser
Junior Member
 
Status: Offline
Posts: 12
Join Date: Jul 2018
Default 07-19-2018, 12:22 AM

Quote:
Originally Posted by chickentree View Post
You have hit on the problem of infinite loops. This is not just in Alice but in almost all programming environments, once an infinite loop starts nothing else can happen until the loop ends - which in the general case is never.
One way around this in Alice is to use events instead of infinite loops. There is no need to have a loop as the event is called by Alice whenever Alice can run it.
Some events, like "While something is true" and "When a variable changes" can be controlled by using variables in the program so that they only act at certain times.
One event that is not obvious is the "While the world is running" this event will be called repeatedly as often as possible while the movie is running.
To use "While the world is running" you first drag a "When the world starts" event into the event list and then Right Click on the event and use the "change to" menu item to change "When the world starts" to "While the world is running." At this point you have an event that will call the method in its "during" section as long as the movie is running. The event has three "slots" any or all of which can be used by the programmer. They are:
  • Begin: Any initialization code goes here
  • During: The method or instructions you want called repeatedly.
  • End: Any event clean-up code that should be done before the movie ends.
One caveat, avoid loops in the event and in methods called by an event. Alice will repeatedly call the event thus giving you the same effect as a loop. While a loop within an event might seem to work it can also lead to several nasty bugs and cause the movie to slow down or even grind to a halt. So just include the code you would put inside a loop in the event and trust Alice to call it repeatedly.

Mark
I had to read that a couple of times but I think I understand what you mean. Thanks for the information. I'll have to keep that in mind. I'll likely end up using it at some point in the future.
   
Reply With Quote