Simple Countdown Timer help
#1
Posted 16 April 2013 - 03:13 AM
Cheers.
#2
Posted 16 April 2013 - 03:25 AM
For The redstone Signal Part i can help when im back Home or you check The Wiki for os.pullevent or rs.getInput
I recommend the code that thebit posted. This method is unessecary for your case
local Countdown = 45 local Start = math.floor(os.clock()) local running = 0 while true do running = math.floor(os.clock()) - Start print("Next Train arrives in " ..Countdown - running .."seconds" sleep(0.5) end
#3
Posted 16 April 2013 - 03:30 AM
LordIkol, on 16 April 2013 - 03:25 AM, said:
local Countdown = 45
local Start = math.floor(os.clock())
local running = 0
while true do
running = math.floor(os.clock()) - Start
print("Next Train arrives in " Countdown - running .."seconds"
sleep(0.5)
end
local count = 45 while true do print('Next train arrives in '..count..' seconds') sleep(1) count = count - 1 if count < 0 then count = 45 end end
EDIT: Also even though you are on your phone you can still type [code][/code] tags, so please use them, you should know that by now!
Edited by theoriginalbit, 16 April 2013 - 03:31 AM.
#4
Posted 16 April 2013 - 03:41 AM
And Even on The Road i normally use my Pad.
i will edit in 30 mins.
And for The Sleep over os.clock you are right. My mind was still at my own project. Where i need to interact with The screen while counting down.
i should Sleep more
#5
Posted 16 April 2013 - 04:14 AM
local mon = peripheral.warp ("back") local count = 45 while true do print('Next train arrives in '..count..' seconds') sleep(1) count = count - 1 if count < 0 then count = 45 end end
#6
Posted 16 April 2013 - 05:04 AM
Try:
local mon = peripheral.wrap("back") local count = 45 while true do mon.clear() mon.setCursorPos(1,1) mon.write('Next tran arrives in '..count..' seconds') count = count - 1 if count < 0 then count = 45 end end
btw, you wrapped it wrong:
(local mon = peripheral.warp ("back"))
should be
(local mon = peripheral.wrap("back"))
I hope i could help!
#7
Posted 16 April 2013 - 05:39 AM
Mikk809h, on 16 April 2013 - 05:04 AM, said:
Try:
local mon = peripheral.wrap("back") local count = 45 while true do mon.clear() mon.setCursorPos(1,1) mon.write('Next tran arrives in '..count..' seconds') count = count - 1 if count < 0 then count = 45 end end
btw, you wrapped it wrong:
(local mon = peripheral.warp ("back"))
should be
(local mon = peripheral.wrap("back"))
I hope i could help!
okay thanks! having issues with line 5 though,
(mon.clear())"too long without yeilding" plus im at a loss when it comes to trying to trigger the countdown with a redstone singal, looked at the wiki for rs.getinput but my coding knowledge is boderline laughable
#8
Posted 16 April 2013 - 05:48 AM
It gives this error because the code needs to yield every 10 (?) seconds. This prevents over CPU usage of the server
#9
Posted 16 April 2013 - 06:28 AM
#10
Posted 16 April 2013 - 08:25 AM
local mon = peripheral.wrap("back") local count = 45 if rs.getInput ("back") == true then mon.clear() mon.setCursorPos(1,1) mon.write('Next tran arrives in '..count..' seconds') sleep(1) count = count - 1 if count < 0 then count = 45 end end
thought this might be a simple fix but alas :/
#11
Posted 16 April 2013 - 08:38 AM
local mon = peripheral.wrap("bottom") local count = 45 if rs.getInput ("back") == true then StopClock(1) end function StopClock() -- while true do mon.clear() mon.setCursorPos(1,1) mon.write('Next train available in '..count..' seconds') sleep(1) count = count - 1 if count < 0 then count = 45 end end
#12
Posted 16 April 2013 - 10:10 AM
I just threw this together, dunno if it works.
local mon = peripheral.wrap("back") local count = 45 function hold() sleep(1) return end function redPulse() os.pullEvent("redstone") return end function count() local current = count while true do mon.clear() mon.setCursorPos(1,1) mon.write('Next train arrives in '..current..' seconds') current = current - 1 if current < 0 then mon.clear() mon.setCursorPos(1,1) mon.write('Next train is arriving...') end local e = parallel.waitForAny(hold, redPulse) if e == 2 then break end end end while true do count() end
#13
Posted 16 April 2013 - 10:28 AM
local mon = peripheral.wrap("back") local count = 45 input = rs.getInput ("front") while true do os.pullEvent("redstone") mon.clear() mon.setCursorPos(1,1) mon.setTextScale(1.5) mon.write("Next departure") mon.write(" ") mon.write(''..count..'s') sleep(1) count = count - 1 if count < 0 then count = 45 end end
i have to use a timer to activate the os.pull line of code set to .2seconds to make the countdown timer seem likes its working in seconds. not ideal but it works, kinda, thanks for the response smiley gonna test it out now, cheers buddy
#14
Posted 16 April 2013 - 10:55 AM
Smiley43210, on 16 April 2013 - 10:10 AM, said:
I just threw this together, dunno if it works.
local mon = peripheral.wrap("back") local count = 45 function hold() sleep(1) return end function redPulse() os.pullEvent("redstone") return end function count() local current = count while true do mon.clear() mon.setCursorPos(1,1) mon.write('Next train arrives in '..current..' seconds') current = current - 1 if current < 0 then mon.clear() mon.setCursorPos(1,1) mon.write('Next train is arriving...') end local e = parallel.waitForAny(hold, redPulse) if e == 2 then break end end end while true do count() end
i pastebined the code into my mc comp and on line 19 there was an error. concatenate string error. i didnt even know what concatenate means! (thank you google define) that being said, i failed to decipher the error. i think im pretty happy with my crude set up tbh though. very intriguged to see how your coding works though smiley.
thanks
#15
Posted 16 April 2013 - 01:57 PM
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users