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

Program that counts from 100 to 0.

Started by FAKE1007, 25 April 2017 - 01:00 PM
FAKE1007 #1
Posted 25 April 2017 - 03:00 PM
So, today uploading a script of program that i maked by 3 minutes. The sense of program(how you can call it, "test") is to count to 0 and close the program. Here the script go:

local count = 100
while true do
term.clear()
term.setCursorPos(1,1)
print(count)
count = count-1
sleep(0.5)
if count <= 1 then
break
end
end
Maybe will help. Also the part of script can be used in API. :D
Lyqyd #2
Posted 26 April 2017 - 02:08 AM
Moved to Programs.
LDDestroier #3
Posted 26 April 2017 - 12:50 PM
I can't see any use from a countdown timer, but it's a start!

But hey-ho


countDown = function(start)
   for a = start, 1, -1 do
      term.setCursorPos(1,1)
      term.write(a.." ")
      sleep(0.5)
    end
end

One things that's useful to note is that for loops can have steps, in the format:

for variable = start,stop,step do
Step defaults to 1, but counting down can be done by having the step be -1. It took me a while to realize that myself.
Edited on 26 April 2017 - 10:54 AM