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

Close mine doors from house

Started by Slyth, 06 May 2012 - 02:03 PM
Slyth #1
Posted 06 May 2012 - 04:03 PM
Ok, this is my first legit program, and what it lets you do is close your mine doors right from your house.
Useful if your like me and always forget to close your doors.
Just hook up redstone underneath the computer to your mine door.
Here it is:

term.clear()
term.setCursorPos(1,1)
print("Open Mine doors or close them?Type close to close and open to open.")
if  redstone.getInput("bottom") == true then
print("Right now, the doors are open.")
else
print("Right now, the doors are closed.")
end
text=io.read()
if text=="open" then
redstone.setOutput("bottom" , true)
end
if text=="close" then
redstone.setOutput("bottom" , false)
end
if redstone.getInput ("bottom") == true then
print("Doors are closed.")
else
print("Doors are open.")
end

Well there you go.
MY first actually good program, feel fine to play around with it and post what you have done with it here!
Im completely open to suggestions.
cant_delete_account #2
Posted 06 May 2012 - 07:16 PM
Made it a bit fancier (the GUI, at least):

function cls()
term.clear()
term.setCursorPos(1,1)
end
function rState()
if rs.getInput("bottom") then
return "open"
else
return "closed"
end
end
cls()
print("Open mine doors or close them?")
print("Hit C to close, O to open.")
print("Hold CTRL+T to quit program.")
while true do
local evt, p = os.pullEvent()
if evt == "key" and p == 24 then
  term.setCursorPos(1,4)
  term.clearLine()
  term.write("Currently "..rState()..".")
  rs.setOutput("bottom" , true)
elseif evt == "key" and p == 46 then
  term.setCursorPos(1,4)
  term.clearLine()
  term.write("Currently "..rState()..".")
  rs.setOutput("bottom", false)
elseif evt == "terminate" then
  cls()
  print("Exited.")
  error()
end
end
Slyth #3
Posted 06 May 2012 - 07:48 PM
Thats pretty neat! Thanks, every time you guys tweak my programs I learn more.