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

What Am I Doing Wrong?

Started by TheNabwoodKidd, 23 February 2012 - 10:45 AM
TheNabwoodKidd #1
Posted 23 February 2012 - 11:45 AM
Hello all, i was using a code for a simple door lock, and was wondering why the door wont close after the time limit?

Spoiler

local function clearScreen()
		term.clear()
		term.setCursorPos(1, 1)
end
while true do
		clearScreen()
		print ("Type password to enter:")  
		if read("*") == "asdf" then				  
				clearScreen()
				print("Correct Password!")
				print("Open door for how long?")
				local a = read()
				clearScreen()
				print("Opening door!")
				sleep (1)
				redstone.setOutput("left", true)		
				clearScreen()
				sleep (a)
		else
				clearScreen()
				print("Incorrect Password, please try again.")
				sleep (5)
		end
end
Espen #2
Posted 23 February 2012 - 12:19 PM
redstone.setOutput() does not send a redstone pulse, but turns on the redstone output permanently.
The only way to turn it off again to do so manually, or to turn off the computer (which turns off all outputs for that computer).

In your code, to manually turn off the redstone signal again (after it has been turned on), add this…
redstone.setOutput("left", false)
… after …
sleep(a)

Like this:
Spoiler

local function clearScreen()
	term.clear()
	term.setCursorPos(1, 1)
end
while true do
	clearScreen()
	print ("Type password to enter:")  
	if read("*") == "asdf" then				  
		clearScreen()
		print("Correct Password!")
		print("Open door for how long?")
		local a = read()
		clearScreen()
		print("Opening door!")
		sleep (1)
		redstone.setOutput("left", true)		
		clearScreen()
		sleep (a)
		redstone.setOutput("left", false)
	else
		clearScreen()
		print("Incorrect Password, please try again.")
		sleep (5)
	end
end

EDIT: Changed explanation at the top.
Edited on 23 February 2012 - 11:23 AM
TheNabwoodKidd #3
Posted 23 February 2012 - 12:48 PM
That worked how i wanted it too, thanks!