|
Pages: [1]
|
 |
|
Author
|
Topic: Countdown to...! (Read 1516 times)
|
|
leke
|
Hi, I was trying to make a kind of countdown timer in console that asked for a time period from the user then visually counted it down (in seconds) to zero. I did have a go, but I am far to embarrassed to show my lame effort! Thanks, L.
|
|
|
|
|
Logged
|
|
|
|
|
CarlRead
|
Blugh - just realised you said "in the console". After I'd written this View counter... rebol [] view layout [ counter: field "0" rate none feel [ engage: func [face action event][ if action = 'time [ face/text: to-string count show face count: count - 1 if count = 0 [counter/rate: none] ] ] ] button "Start" [ count: 10 counter/rate: 1 show counter ] ]
The following almost, but not quite does at the console what I think you want done... rebol [] prin "Enter number: " count: to-integer input while [count > 0][ print count: count - 1 wait 1 ]
I'm sure there's a way to have the numbers stay on the same line - I just don't know how to do it. I think there's console instructions in the Core user-guide, so they might tell you.
|
|
|
|
« Last Edit: June 09, 2004, 05:09:34 AM by CarlRead »
|
Logged
|
- Carl Read
|
|
|
|
Sunanda
|
getting them to stay on one line is easy: rebol [] prin "Enter number: " count: to-integer input while [count > 0][ prin [count: count - 1 " "] wait 1 ]
Getting them to overwrite each other is a bit tricky. As you say, console positioning may be the way. Here's one useful reference: http://www.rebolforces.com/articles/tui-dialect.htmlBut the timer runs slighty slower than once per second. For precison countdowns the wait should be reduced by the time it takes to execute the other instructions in the loop. You can see the problem here: rebol [] prin "Enter number: " count: to-integer input while [count > 0][ prin [count: count - 1 "(" now/time/precise ") "] wait 1 ]
|
|
|
|
|
Logged
|
|
|
|
|
Gabriele
|
It's not tricky at all actually, you just need a carriage return, like: repeat i 10 [prin i prin CR wait 1] print ""
|
|
|
|
|
Logged
|
|
|
|
|
leke
|
|
|
|
|
« Last Edit: June 15, 2004, 05:34:19 AM by leke »
|
Logged
|
|
|
|
|
leke
|
OK, I chucked Gabriele’s code in with Sunanda’s to get...
rebol [] prin "Enter number: " count: to-integer input while [count > 0][prin [count: count - 1 prin CR] wait 1]
but I get ?unset? next to the number. What does this mean and how do I get rid of it? Thanks, L.
|
|
|
|
|
Logged
|
|
|
|
|
Gabriele
|
You have one extra prin. Your code should read: while [count > 0][prin [count: count - 1 CR] wait 1]
|
|
|
|
|
Logged
|
|
|
|
|
|
|
|
Pages: [1]
|
|
|
 |
News: 01-09-08 Alpha version of REBOL 3 has been released!
2295 Posts in 593 Topics by 3763 Members
Latest Member: svolika
|