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

"0" at the end

Started by Kristopher_Jones, 31 October 2015 - 03:23 PM
Kristopher_Jones #1
Posted 31 October 2015 - 04:23 PM
Hello i got again problem.
Check time.
When time is more than 10 all behave good but if there are less than 10 min time moves one space left and makes dot at the end.
Dot - i made as function but if i remove this function then at the end apears "0"
How i can fix it ? at least remove this "0"
Photos:



Spoilerprint("Set countdown to game") –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")

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",true)
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)

–Returning Results
mon.setTextScale(5)

mon.setCursorPos(7,5)

mon.write(min..":"..sec)

until j == 0 and i == 0
mon.setCursorPos(8,3)

mon.write("1")
rs.setOutput("right",true) – trigger redstone output
sleep(1)

end
Edited on 31 October 2015 - 03:24 PM
Dog #2
Posted 31 October 2015 - 04:41 PM
The easiest way to do this would be to change

mon.write(min..":"..sec)

to

mon.write(min..":"..sec.." ")

By adding a space to the end, you'll overwrite that 0 when the time changes from 4 digits to 3 digits.
Kristopher_Jones #3
Posted 31 October 2015 - 04:44 PM
WOW, worked, thank you!