Alice Community  

Go Back   Alice Community > Alice 2 > How do I...?

Reply
 
Thread Tools Display Modes
Stop infinity!
Old
sephiroth88
Guest
 
Status:
Posts: n/a
Default Stop infinity! - 02-15-2007, 08:49 AM

Help i am writing a musical program but im using loop infinitys. Is there any possible way to stop loop infinitys. What i am trying to do is pause all the actions but i have used so many loops i dont know the exact spot to stop it all or even the code.
   
Reply With Quote
avoiding inifinte loops
Old
chuck
Guest
 
Status:
Posts: n/a
Default avoiding inifinte loops - 02-15-2007, 09:37 AM

Events are often a good alternative to loops that run continuosly. Take a look at some of the events in the flightSimulator on Alice's Examp[les tab.

For instance:

While World.WindMillIsOn is true
Begin: Nothing
During: windmill.Blades roll at speed left speed = 0.25 revolutions per second
End: Nothing

The programmer set up a Boolean property named World.WindMillIsOn and this eevent effectively loops the instruction as long as the variable is true.

Another event could set set up to change the value of the property based on a key press or mouse click.

"While the world is running" is another alternative to inifinte loops. You can create this event by right clicking on a "When the world starts" event.

I hope this helps.

Chuck Herbert
   
Reply With Quote
Related Question
Old
DrJim
Guest
 
Status:
Posts: n/a
Question Related Question - 02-15-2007, 10:01 AM

Let me add a related question about something that keeps puzzling me. If I do set up an event-type "while" such as (please excuse the pseudo code):

While any key is pressed
Begin: Nothing
During: Condition=true
End: Condition=false

when (and how often) is the while condition tested (i.e., how long is it after I release the key before "condition" goes to false)?

It's obviously a fairly rapid thing - but how fast. (In particular, is it for every frame from the graphics card or is there some buffering effect?)
   
Reply With Quote
Old
chuck
Guest
 
Status:
Posts: n/a
Default 02-17-2007, 08:58 AM

Hello Dr. Jim,

Alice is a cross-platform programming environment, so the answer to that question depends on the platform -- both the specific operating system and the hardware, particularly the I/O hardware. Alice uses features in the programming languages used to create the Alice system, which in turn rely on features of the operating system, some of which rely on the hardware.

I did a few experiments with Alice on a Windows XP PC with a 3.0 Ghz processor and 1Gb of RAM, and found that Alice was responding to changes in the state of a Boolean variable in an average of about .015 seconds. I added ten objects to the world with separate events to keep each of them moving, and found that the results were the same. As far as I could tell, the presence of ten moving objects and ten additional events had no measurable effect on the time it took Alice to respond to the changes in state of a Boolean variable. At some point, perhaps when most of the memory is used up, the number of objects and events should affect response time. Responses time wil probably degrade with complicated texture maps and longer sound files added to a world.

I did notice that there is a pasue of about 1/3 of a second seconds when the the world first starts with the ten objects and ten events added. After that initial "time burp", the response times were the same with or without the added objects and events.

The fastest that someone can “tap” a key -- press the key and let go, is in the magnitude of 1/10th of a second. With modern CPU cycles in billionths of a second, even a million cycles takes less time than that. A rough answer is to your question is that Alice events seems to be fast enough so that other factors will constrict its response to events.

This doesn’t answer your question in terms of graphics refresh cycles, but it may help.
   
Reply With Quote
Thanks for the response.
Old
DrJim
Guest
 
Status:
Posts: n/a
Exclamation Thanks for the response. - 02-17-2007, 09:21 AM

Thank you very much for your detailed answer - it not only gave me the information I needed to proceed with a project I had in mind but inspired me to try an experiment of my own in the next few days (to see how playing sound does affect the event response).

In particular the information that "ten additional events had no measurable effect on the time it took Alice to respond to the changes" turns out to be exactly the information I needed - though that wasn't even the question I asked. Thanks again.
   
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Copyright ©2019, Carnegie Mellon University
Alice 2.x © 1999-2012, Alice 3.x © 2008-2012, Carnegie Mellon University. All rights reserved.