Rebol Talk Forum  |  Getting Started  |  Newbie Help  |  Topic: Countdown to...!
Pages: [1] Print
Author Topic: Countdown to...!  (Read 1474 times)
leke
Jr. Member
**
Offline Offline

Posts: 90


View Profile WWW
Countdown to...!
« on: June 09, 2004, 01:35:38 AM »

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
Full Member
***
Offline Offline

Posts: 105


View Profile
Countdown to...!
« Reply #1 on: June 09, 2004, 05:08:17 AM »

Blugh - just realised you said "in the console".  After I'd written this View counter...
Code:
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...
Code:
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
Full Member
***
Offline Offline

Posts: 100


View Profile
Countdown to...!
« Reply #2 on: June 09, 2004, 06:14:15 AM »

getting them to stay on one line is easy:
Quote
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.html

But 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:

Quote
rebol []
prin  "Enter number: "
count: to-integer input
while [count > 0][
  prin [count: count - 1 "(" now/time/precise ") "]
  wait 1
]

 
Logged
Gabriele
Full Member
***
Offline Offline

Posts: 182


View Profile WWW
Countdown to...!
« Reply #3 on: June 09, 2004, 08:35:06 AM »

It's not tricky at all actually, you just need a carriage return, like:

Code:
repeat i 10 [prin i prin CR wait 1] print ""
Logged
leke
Jr. Member
**
Offline Offline

Posts: 90


View Profile WWW
Countdown to...!
« Reply #4 on: June 15, 2004, 01:38:34 AM »

Wink  
« Last Edit: June 15, 2004, 05:34:19 AM by leke » Logged

leke
Jr. Member
**
Offline Offline

Posts: 90


View Profile WWW
Countdown to...!
« Reply #5 on: June 15, 2004, 05:32:35 AM »

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
Full Member
***
Offline Offline

Posts: 182


View Profile WWW
Countdown to...!
« Reply #6 on: June 15, 2004, 06:08:29 AM »

You have one extra prin. Your code should read:

Code:
while [count > 0][prin [count: count - 1 CR] wait 1]
Logged
leke
Jr. Member
**
Offline Offline

Posts: 90


View Profile WWW
Countdown to...!
« Reply #7 on: June 16, 2004, 01:19:31 AM »

Thanks  Cheesy  
Logged

Pages: [1] Print 
Rebol Talk Forum  |  Getting Started  |  Newbie Help  |  Topic: Countdown to...!
Jump to:  

  
Quick Search...

Advanced search
  
Welcome, Guest. Please login or register.
Did you miss your activation email?
August 29, 2008, 03:11:57 AM
Username: Password: Session Length:
  

News: 01-09-08

Alpha version of REBOL 3 has been released!


  
2232 Posts in 580 Topics by 1736 Members
Latest Member: goceertarramy

  Rebol Talk Forum | Powered by SMF 1.0.9.
© 2001-2005, Lewis Media. All Rights Reserved.

RT design by Defiant Pc