1 posts
Posted 29 August 2012 - 04:42 AM
Hello I'm new so hi.
Anyways I'm a complete novice when it comes to coding, I can barely code a password lock for a door.
I have been searching the internet for a premade code on how to have the computer countdown 3(ish) hours, well 2 hours and 50 minutes to be precise, then send out a redstone pulse from the back then sleep for like 5 minutes and on an infinite loop. So once it is done sleeping it restarts itself and that goes on forever, well that's the dream atleast. Also with the remaining time displaying on a monitor.
Any help would be greatly appreciated :)/>/>
37 posts
Location
Sweden
Posted 01 September 2012 - 11:25 PM
while true do --Loops the program
sleep(10200) --Sleeps for 2h50m
rs.setOutput("back", true) --Activates the back
sleep(300) --Stay activated for 5m
rs.setOutput("back", false) --Deactivates the back
end
There you go!
66 posts
Posted 02 September 2012 - 04:51 AM
m = 50
h = 2
for i=1, 170 do --170m = 2h50m
term.clear() --clears the screen
term.setCursorPos(1, 1) --sets the cursor to 1,1
print("Hours: "..h) --prints how many hours are left
print("Minutes: "..m) -- prints how many minutes are left
sleep(60) --sleeps for 1m
if m == 0 then --if the minutes hit 0 then it set minutes to 60 and hours to hours -1
h = h-1
m = 60
end
m = m-1 --makes m one less then m
end
just do monitor (side of computer the monitor is on) (what you named the program)
144 posts
Location
Wellington, New Zealand
Posted 02 September 2012 - 11:21 AM
I tried making one too! :)/>/> But, I'm not very good with lua so this is probably really bad B)/>/> Sorry if I did it wrong..
h = 2
m = 49
s = 60
function check()
if s <= 0 then
m = m -1
s = 60
end
if m < 0 then
h = h-1
m = 60
end
if h < 0 then
print("Standing By...")
redstone.setOutput("back", true)
sleep(1)
redstone.setOutput("back", false)
sleep(300)
h = 02
m = 49
s = 60
end
end
while true do
term.clear()
term.setCursorPos(1,1)
print(h..":"..m..":"..s)
sleep(1)
s = s-1
check()
end
Just run that on the monitor B)/>/>
Edit: Oh and.. If someone could point out what I could do better.. That would be great :)/>/> I'm trying to get better.
66 posts
Posted 02 September 2012 - 11:26 AM
I tried making one too! :)/>/> But, I'm not very good with lua so this is probably really bad B)/>/> Sorry if I did it wrong..
h = 2
m = 49
s = 60
function check()
if s <= 0 then
m = m -1
s = 60
end
if m < 0 then
h = h-1
m = 60
end
if h < 0 then
redstone.setOutput("back", true)
sleep(1)
redstone.setOutput("back", false)
sleep(300)
h = 02
m = 49
s = 60
end
end
while true do
term.clear()
term.setCursorPos(1,1)
print(h..":"..m..":"..s)
sleep(1)
s = s-1
check()
end
Just run that on the monitor B)/>/>
Edit: Oh and.. If someone could point out what I could do better.. That would be great :)/>/> I'm trying to get better.
you may want to switch
if h < 0 then
redstone.setOutput("back", true)
sleep(1)
redstone.setOutput("back", false)
sleep(300)
h = 02
m = 49
s = 60
end
to
if h == 0 and m ==0 and s == 0 then
redstone.setOutput("back", true)
sleep(1)
redstone.setOutput("back", false)
sleep(300)
h = 02
m = 49
s = 60
end
i think that should work
144 posts
Location
Wellington, New Zealand
Posted 02 September 2012 - 11:38 AM
Isn't it basically the same thing? Since it won't print anything once the hour is -1. So it'll show up the same?
Edit: I changed some of the code so that it won't just stay frozen at 0:0:1. The first post I made has been updated :)/>/>
Edit 2: Also, You could save this:
shell.run("monitor", "right", "timer")
as a program called 'startup' and it would automatically start the program on the monitor. Remember to change "right" to whatever side you have the computer on and "timer" to whatever you named the program.