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

need help with a door

Started by 1jedisithlord1, 22 February 2015 - 06:36 PM
1jedisithlord1 #1
Posted 22 February 2015 - 07:36 PM
Hi there, i'm trying to figure out how to make a door open and close, but being a complete failure at writing computercraft code, or any code for that matter, I seem to be failing, if someone could either point me to a good tutorial on how to do this, or even give me some code that will do it, that would be greatly appreciated, all i'm trying to get it to do is open and close a door based on a monitor button, such as you push it once and it opens the door, then you push the button again and it closes the door, just 2 monitors, one is 14 blocks away from the door mechanism and the other would be right next to it, the door itself is a set of 3 drawbridges extending out to make a drawbridge of sorts, im running it from the direwolf20 1.7.10 ftb modpack, if that changes anything. Thank you for any and all help provided.
Bomb Bloke #2
Posted 23 February 2015 - 01:16 AM
A (very basic) way of doing it:

rs.setOutput("back", false)  -- Make sure there's no redstone signal out the back when we start.

local mon = {peripheral.find("monitor")}  -- Take all available monitors, stick them in a table.

for i = 1, #mon do  -- For each monitor in the table,
	mon[i].setBackgroundColour(colours.red)
	mon[i].clear()  -- Clearing sets the display to the current background colour.
end

while true do  -- Start a loop that repeats indefinitely.
	os.pullEvent("monitor_touch")  -- Wait for someone to touch a monitor.
	
	rs.setOutput("back", not rs.getOutput("back"))  -- Set the output to the opposite of what it was.
	
	for i = 1, #mon do
		if rs.getOutput("back") then   -- If the output is on, then:
			mon[i].setBackgroundColour(colours.green)
		else -- or if it's off:
			mon[i].setBackgroundColour(colours.red)
		end
		
		mon[i].clear()
	end
end

Place wired modems on each monitor and the computer (any side), and connect them together with network cable. Use (right-click) the modems on the monitors to "connect" them. Hook up your redstone dust/wire/whatever to the back of the computer.