Quote:
Originally Posted by shaolinkidd
I can get the cone to catch the ring but my program does not repeat after the ring is caught. Do you think you can help me with this? I've included my program.
|
I am not sure of the exact requirements for this project so I am shooting from the hip.
In order to drop another ring ask yourself what has to happen. In the general case this can be broken down into the following:
Initialize the movie
Set the items, variables etc to their initial values.
In a great many cases you can do this in the Alice IDE (while you are authoring the movie.)
Start the looping part.
Make sure things are initialized (objects in their proper place, variables have the correct values.) Remember the instructions will be repeated so the movie will probably not be in the same configuration when it starts through the loop on the second or subsequent runs.
Do the instructions you want to repeat.
In the general programming case one or more of these instructions will result in changes that will cause the loop to end. Alice’s interactive nature provides other options, like the one demonstrated in the attached movie.
Check the conditions to see if the loop is done
Continue with the rest of the program.
In general any loop whether a ‘for’ loop, a ‘while’ loop or some other more exotic type has to accomplish a couple of things. It must repeatedly perform the operations it was designed to do. And it must have a way to end when it has repeated ‘enough’ times.
In a lot of cases we know (or can calculate) how many times the loop will need to repeat and in these cases a ‘for’ loop is great. But what if we do not know how many times the operations must be repeated? In that case we need to do something different. This is where the ‘while’ loop comes in. The while loop uses a Boolean value (called a monitor) to determine whether to run the loop and if so when to stop. The key here is that this value (the monitor) must initially be true, or the instructions within the while loop will never be run, and some action must be capable of changing the monitor from true to false in order to end the loop. This action can be something within the loop that signals the the desired condition has been met or it can be an ‘external’ event that changes the value the monitor is using to tell whether to continue.
In the movie I have attached the loop is controlled by an outside event (clicking on the rabbit.)
Using the logic operators and object properties and functions you can make the continuation of your while loop depend on one or several conditions being true or false so you have a lot of control over whether the loop continues or not.
Be aware that if you are looping you may need to set things up each time the loop repeats. In your case, if the cone and ring are not moved back to their starting positions at the beginning of the loop, they will be wherever they were when the last loop ended.
Hope this helps.
Mark