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

Pause clock.

Started by Kristopher_Jones, 11 April 2016 - 05:34 PM
Kristopher_Jones #1
Posted 11 April 2016 - 07:34 PM
Please, how can i make that when lever are down time goes but if lever again puts up it exit the program and goes back onother command called "m"


print("Set game time") --only need minutes
print("Minutes?") --only need minutes
write("-> ")
minute = tonumber(read()) --input directly as number(avoid string)
print("Seconds") --only need minutes
write("-> ")
sec = tonumber(read()) --input directly as number(avoid string)
print("Time added, press button to start countdown")
print("STOP TIME- ctrl + t then m ")
mon.setCursorPos(8,3)
mon.write("1")
local j = sec   --declare seconds variable
local i = minute   ---declare minutes variable
min = i
		    sleep(1)
		    --Returning Results
		    mon.setTextScale(5)
		 
		    mon.setCursorPos(7,5)
		    mon.write(min..":"..sec)

    os.pullEvent("redstone")
    if rs.getInput("left") then
    rs.setOutput("right",false)
repeat
		  
		    if i > 0 then
						    if j > 0 then
										    j = j - 1
						    else
										    j = 59
										    i = i - 1
						    end
		    else
						    if j > 0 then
										    j = j - 1
						    else
										    done = true
						    end
		    end
		    if j > 9 then
						    sec = j
		    else
						    sec = "0"..j
		    end
		    min = i
		    sleep(1)
  if i < 10 then
mon.setCursorPos(11,5)
		    mon.write(".")
end
		    --Returning Results
		    mon.setTextScale(5)
		
				 mon.setCursorPos(6,5)
		  
		    mon.write(min..":"..sec.." ")
		    until j == 0 and  i == 0
rs.setOutput("top",true)
rs.setOutput("right",true) 
sleep(2)
rs.setOutput("top",false)
						 -- trigger redstone output
sleep(1)
end
KingofGamesYami #2
Posted 11 April 2016 - 07:41 PM
Spent a few minutes fixing your formatting:
Spoiler

print("Set game time") --only need minutes
print("Minutes?") --only need minutes
write("-> ")
minute = tonumber(read()) --input directly as number(avoid string)
print("Seconds") --only need minutes
write("-> ")
sec = tonumber(read()) --input directly as number(avoid string)
print("Time added, press button to start countdown")
print("STOP TIME- ctrl + t then m ")
mon.setCursorPos(8,3)
mon.write("1")
local j = sec   --declare seconds variable
local i = minute   ---declare minutes variable
min = i
sleep(1)
--Returning Results
mon.setTextScale(5)

mon.setCursorPos(7,5)
mon.write(min..":"..sec)

os.pullEvent("redstone")
if rs.getInput("left") then
    rs.setOutput("right",false)
    repeat

        if i > 0 then
            if j > 0 then
                j = j - 1
            else
                j = 59
                i = i - 1
            end
        else
            if j > 0 then
                j = j - 1
            else
                done = true
            end
        end
        if j > 9 then
            sec = j
        else
            sec = "0"..j
        end
        min = i
        sleep(1)
        if i < 10 then
            mon.setCursorPos(11,5)
            mon.write(".")
        end
        --Returning Results
        mon.setTextScale(5)

        mon.setCursorPos(6,5)

        mon.write(min..":"..sec.." ")
    until j == 0 and  i == 0
    rs.setOutput("top",true)
    rs.setOutput("right",true) 
    sleep(2)
    rs.setOutput("top",false)
    -- trigger redstone output
    sleep(1)
end

You'll need to add a check to 'until' for the redstone signal.