Countdown Timer For A Spawner
#1
Posted 11 September 2013 - 08:31 AM
i want to do exactly this:
Button is pressed and redstone signal goes to computer
computer starts a countdown (of 5 minutes) and displays the countdown on the screen next to it
while this countdown is active i would like an active redstone pulse from another side.
when the countdown hits zero the screen will say "Press button to start spawner"
The redstone pulse will then turn off until button is pressed again.
If anyone can help me this would be much appreciated :>
#2
Posted 11 September 2013 - 11:30 AM
Well, the simplest version of this would basically just check the redstone input on the side of the button, then output a redstone signal on another side and use sleeps or timer events to deal with the timer display. You should start with the redstone API page in the wiki and check out the sleep page and term API page for drawing to the screen.
#3
Posted 11 September 2013 - 06:48 PM
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()
endthere were a lot of errors to begin with but so far i have:
local mon = peripheral.wrap("right")
local x,y = mon.getSize()
local count = 300
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( x / 2 - 26 / 2 + (26 % 2 == 0 and 0 or 1), 1)
mon.write("Mobs will stop spawning in")
mon.setCursorPos( x / 2 - 10 / 2 + (10 % 2 == 0 and 0 or 1), 2)
mon.write(current "seconds")
current = current - 1
if current < 0 then
redstone.setOutput(back, false)
mon.clear()
mon.setCursorPos( screen_width / 2 - 21 / 2 + (21 % 2 == 0 and 0 or 1), 1)
mon.write("Mobs have been paused")
end
local e = parallel.waitForAny(hold, redPulse)
if e == 2 then
break
end
end
end
while true do
count()
end
my problems are that mon.write("current seconds")
"current" didnt place to the number of secondsalso line 23
current = current - 1i have an error on attempt to perform arithmetic __sub on function and number
#4
Posted 11 September 2013 - 08:29 PM
Your first problem is that in:
mon.write("current seconds")
current is actually a string, or a word, instead of a variable. To fix this simply put current out of the string like this:
mon.write(current .. "seconds")
Why the "current = current-1" thing isn't working.. No clue sorry :S
#5
Posted 11 September 2013 - 10:29 PM
local current = count
That's what's causing the error. A variable only holds one thing at a time.
#6
Posted 12 September 2013 - 03:33 AM
ikke009, on 11 September 2013 - 08:29 PM, said:
Your first problem is that in:
mon.write("current seconds")
current is actually a string, or a word, instead of a variable. To fix this simply put current out of the string like this:
mon.write(current .. "seconds")
Why the "current = current-1" thing isn't working.. No clue sorry :S
Lyqyd, on 11 September 2013 - 10:29 PM, said:
local current = count
That's what's causing the error. A variable only holds one thing at a time.
#7
Posted 12 September 2013 - 07:17 AM
Change local count = 300 (at the start of the program) to "counter = 300"
then change the local current = count to "local current = counter"
This will avoid any possible mis-translation of the counter and count (varible and function) by Lua. (also note I changed the counter varible into a global varible by removing local from it's declaration)
I would also say that you really do not need to assign the origional "counter" value as all you are doing is later passing a unchanged value to the program. (wastes memory)...
I suggest you scrap the local count = 300 and just write in the first line of the function "local current = 300" instead. as it is exactly the same but you only assign 300 to current and not to count and current.
function count() local current = 300 ... code stuffs end
#8
Posted 12 September 2013 - 07:52 AM
local mon = peripheral.wrap("right")
local x,y = mon.getSize()
function hold()
sleep(1)
return
end
function redPulse()
os.pullEvent("redstone")
return
end
function count()
local current = 300
while true do
mon.clear()
mon.setCursorPos( x / 2 - 26 / 2 + (26 % 2 == 0 and 0 or 1), 1)
mon.write("Mobs will stop spawning in")
mon.setCursorPos( x / 2 - 10 / 2 + (10 % 2 == 0 and 0 or 1), 2)
mon.write(current "seconds")
current = current - 1
if current < 0 then
redstone.setOutput(back, true)
mon.clear()
mon.setCursorPos( screen_width / 2 - 21 / 2 + (21 % 2 == 0 and 0 or 1), 1)
mon.write("Mobs have been paused")
end
local e = parallel.waitForAny(hold, redPulse)
if e == 2 then
break
end
end
end
while true do
count()
end
another problem :<mon.write(current "seconds")i cant get current to replace to be the 1-2 digit number it is suppose to be :<
i get "attempt to call number" error
#9
Posted 12 September 2013 - 08:12 AM
#10
Posted 12 September 2013 - 08:34 AM
CoderPuppy, on 12 September 2013 - 08:12 AM, said:
#11
Posted 12 September 2013 - 09:25 AM
Edit: That line should work if it is:
mon.write(current .. "seconds")
#12
Posted 12 September 2013 - 06:16 PM
CoderPuppy, on 12 September 2013 - 09:25 AM, said:
Edit: That line should work if it is:
mon.write(current .. "seconds")
local mon = peripheral.wrap("right")
local x,y = mon.getSize()
function hold()
sleep(1)
return
end
function redPulse()
os.pullEvent("redstone")
return
end
function count()
local current = 300
while true do
mon.clear()
mon.setCursorPos( x / 2 - 26 / 2 + (26 % 2 == 0 and 0 or 1), 1)
mon.write("Mobs will stop spawning in")
mon.setCursorPos( x / 2 - 10 / 2 + (10 % 2 == 0 and 0 or 1), 2)
mon.write(current .. " seconds")
current = (current - 1)
if current < 0 then
redstone.setOutput(back, true)
mon.clear()
mon.setCursorPos( screen_width / 2 - 21 / 2 + (21 % 2 == 0 and 0 or 1), 1)
mon.write("Mobs have been paused")
end
local e = parallel.waitForAny(hold, redPulse)
if e == 2 then
break
end
end
end
while true do
count()
end
here are the next problems:i once the timer gets to zero it says
startup:40: Expected string, bolean
also this bit of code didnt seem to take place
if current < 0 then
redstone.setOutput(back, true)
mon.clear()
mon.setCursorPos( screen_width / 2 - 21 / 2 + (21 % 2 == 0 and 0 or 1), 1)
mon.write("Mobs have been paused")
#13
Posted 13 September 2013 - 02:48 AM
#15
Posted 13 September 2013 - 09:57 AM
local timers = {}
term.clear()
term.setCursorPos(1,1)
print("Spawner Timer Delux")
print("----------------------------")
print("Press button for teh mobz...")
local function output(text)
term.setCursorPos(1,3)
term.clearLine()
term.write(text)
end
local function begin(seconds)
timers = {}
for i=0,seconds - 1 do
timers[os.startTimer(seconds-i)] = i
end
redstone.setOutput("back", true)
output("Spawner on for next "..tostring(seconds).." seconds...")
end
while true do
event, p1, p2 = os.pullEvent()
if event == "timer" then
if timers[p1] == 0 then
output("Press button for teh mobz...")
redstone.setOutput("back", false)
else if timers[p1] then
output("Spawner on for next "..tostring(timers[p1]).." seconds...")
end
end
if event == "redstone" and redstone.getInput("back") then
begin(300)
end
end
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











