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

Timer Question

Started by JohnnyX, 24 June 2013 - 12:27 PM
JohnnyX #1
Posted 24 June 2013 - 02:27 PM
Well , I am making the Swan station from LOST and I'm kinda stuck at the timer part (and the periscope but i made another post for that :D/>). Here's the code:

--Swan Station Timer	
term.clear()	
term.setCursorPos(1,1)	
m = peripheral.wrap("front")	
minutes = 1	
seconds = 0	
	
function Xtimer(seconds, minutes, monitor) --a timer function	
monitor.clear() 	
monitor.setCursorPos(3, 3)	
  seconds = seconds - 1	
  if (minutes == 0 and seconds == -1 ) then	
  seconds = 0	
  end	
  if(seconds < 0) then	
	seconds = 59	
	minutes = minutes - 1	
   elseif(seconds == 0) then	
	 seconds = tostring(00)	
	 end	
	 if(seconds < 10) then	
	 seconds = "0"..tostring(seconds)	
	 end	
  monitor.write(minutes..":"..seconds)	
seconds = tonumber(timer)	
os.sleep(1)	  
	
end	
	
timer = os.startTimer(60)	
	
print("Initializing timer...")	
os.sleep(1)	
	
while(true) do	
	
  if (redstone.getInput("left") and minutes < 4) then	
  print("Reseting...")	
  end 	
  if (minutes < 0 and seconds == 0) then	
  write("System Failture")	
  end	
	
  Xtimer(seconds, minutes, m) -- calling the timer function	  
end

it just wont work. It displays 0:59 and then nothing happens.
JohnnyX #2
Posted 24 June 2013 - 04:21 PM
Nevermind, I found what the problem was. I couldn't use the function this way. I fixed it now and I polished it. I may upload a video :D/>