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

Counter?

Started by Bennievv, 26 February 2012 - 06:40 AM
Bennievv #1
Posted 26 February 2012 - 07:40 AM
I wanted to make a clock, but how can I make my computer count, and can reset?

:)/>/>
Bennievv
Espen #2
Posted 26 February 2012 - 10:57 AM
This is just one of many ways to do it:

local counter = 1 --Starting value

while true do
  term.setCursorPos( 1, 1 )   -- (Re-)set cursor position
  term.clear()   -- (Re-)clear screen
  print( "Counter = "..counter )
  print( "Press ENTER to continue..." )
  read()
  counter = counter + 1   -- Increment counter
  if counter > 10 then break end  -- Ends the loop when the counter surpasses 10.
end
Basically, you just create a numerical variable with a starting value and then increment it by your desired amount every time you want to count up, or decrement it if you'd like to go the other direction.^^

EDIT: Added a break condition.
Edited on 26 February 2012 - 09:59 AM
Bennievv #3
Posted 26 February 2012 - 12:22 PM
Oh, huge thanks! :D/>/>