This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
sleawnis's profile picture

Silly question while true loop

Started by sleawnis, 25 November 2013 - 03:48 PM
sleawnis #1
Posted 25 November 2013 - 04:48 PM
function sevens()
   countdown()
   sm = 7
   while true do
      sm = sm+7
input = read()
      print(sm)
      sleep(10)
   end
end

What it does: does not allow for text to be input,
What is expected: When the input is placed, the screen will display 7,14 etc… One number per click
MKlegoman357 #2
Posted 25 November 2013 - 04:57 PM
You never call your function. To call your function use:


sevens()
Edited on 25 November 2013 - 03:57 PM
sleawnis #3
Posted 25 November 2013 - 04:59 PM
I have, this was just a snippet
MKlegoman357 #4
Posted 25 November 2013 - 05:00 PM
What does countdown() function look like?
sleawnis #5
Posted 25 November 2013 - 05:01 PM
function countdown()
   clear()
   print("Workout starting in 3 second(s)")
   sleep(1000)
   print("Workout starting in 2 second(s)")
   sleep(1000)
   print("Workout starting in 1 second(s)")
   sleep(1000)
   clear()
end
Lyqyd #6
Posted 25 November 2013 - 05:02 PM
Please post the whole code.

Edit: Sleep is in seconds, so sleep(1000) will sleep for 16 minutes and 40 seconds.
MKlegoman357 #7
Posted 25 November 2013 - 05:04 PM
function countdown()
   clear()
   print("Workout starting in 3 second(s)")
   sleep(1000)
   print("Workout starting in 2 second(s)")
   sleep(1000)
   print("Workout starting in 1 second(s)")
   sleep(1000)
   clear()
end

sleep function waits for seconds not milliseconds. So, your code is waiting for 1000 seconds, then prints "Workout starting in 3 second(s)", then waits another 1000 seconds and so on.
sleawnis #8
Posted 25 November 2013 - 05:13 PM
http://pastebin.com/StTMU1iP
It's designed for a emulator with slightly different API, but you get the idea: http://pastebin.com/StTMU1iP

The API I use uses ms
Bomb Bloke #9
Posted 26 November 2013 - 05:40 AM
So you've overridden sleep(), and presumably provided a clear() function?

Did you also override read() while you were at it, maybe?

What does it do instead of letting you type? Only knowing what it "doesn't" do leaves lots to the imagination.