Hey y'all,

I have just started coding in CelticCE (like last week) and I'm trying to make a screensaver, but I've ran into a few issues.

As of now, here is my code.


Code:
:DCS

While getKey=0

Lbl 1
det(16,RED)
Wait 1
det(16,BLUE)
Wait 1
det(16,GREEN)
Wait 1
det(16,MAGENTA)
Wait 1
det(16,ORANGE)
Wait 1
det(16,BROWN)
Wait 1
det(16,NAVY)
Wait 1
det(16,YELLOW)
Wait 1
det(16,LTBLUE)
Wait 1

End:ClrHome




The problem I have is that whenever I press a key, it doesn't stop immediately, it only stops on the last line (the light blue). I've looked through a lot of things including other screensaver's source code, but I can't find any way how to make it stop right away, not at the end of the code.

Thanks.
There's nothing Celtic-specific here: the condition (getKey=0) for a loop is only evaluated once per iteration, and with a While loop that happens at the top of the loop (Repeat does it at the end). So the sequence of operations is something like:
  1. Is any key pressed? If yes, skip to 4; otherwise continue to 2.
  2. Run code inside loop.
  3. Reach End, go back to 1.
  4. ClrHome and exit


If you want to be able to exit at any time, you'll need to ensure the program is doing key checks at every point you want to be able to exit; a loop doesn't continuously evaluate its condition (which sounds like the behavior you expected).
Thanks a lot for your advice! I added some extra key checks and it works!
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement