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

Constant Redstone Output & Password req. Program

Started by Gomo, 23 November 2014 - 09:25 AM
Gomo #1
Posted 23 November 2014 - 10:25 AM
Hello guys,

I'm new to computercraft and looking for help.
I'm currently working on my Mars base and I have a cool idea (imo), but I cannot figure out how to make it work properly.

Here's the picture:



I got a computer on right side and I'd like to have constant redstone signal on top (for the red lights) -> "no go / closed air lock doors"
And when I right click on it, it asks for the launch permission password, if you enter the correct password it sends a redstone signal on the bottom block for 40 seconds which then lights up the green lights and opens up the air lock frame.
After 40 seconds it reboots/restarts.


I've been honestly trying to make this work.. I spent hours writing my own programs which would then in the end fail,.. every time.
My Computercraft knowldge isn't too great, I know basics.. so therefore I'm asking you guys for help :/

EDIT: This is what I wrote so far:


("edit startup")
while true do
rs.setOutput("top",true)
print("Enter the launch password: ")
password = read()
if password == "blabla" then
print("Launch sequence has been initiated!")
rs.setOutput("top",false)
rs.setOutput("bottom",true)
sleep(40)
rs.setOutput("bottom",false)
os.shutdown()
end


I would really appreciate it! Also, I apologize if I posted this topic in the wrong section.

-kind regards-

Gomo
Edited on 23 November 2014 - 10:05 PM
Lyqyd #2
Posted 23 November 2014 - 09:12 PM
Moved to Ask a Pro.

Please post the code you've written so far.
Bomb Bloke #3
Posted 24 November 2014 - 04:48 AM
You very nearly had it going, but you were lacking an "end" statement.

I'd tweak it a little to look more like this:

rs.setOutput("top",true)
rs.setOutput("bottom",false)

while true do
	print("Enter the launch password: ")
	password = read("*")
	
	if password == "blabla" then
		print("\nLaunch sequence has been initiated!")
		rs.setOutput("top",false)
		rs.setOutput("bottom",true)
		sleep(40)
		rs.setOutput("bottom",false)
		rs.setOutput("top",true)
		print("Launch sequence complete.")
	else
		print("\nInvalid password.")
	end
	
	sleep(3)
	term.clear()
	term.setCursorPos(1,1)
end

Passing "*" to the read function makes it obscure whatever you type in.

The while loop removes any need to reboot the system - it handles the repetition for you.
Gomo #4
Posted 24 November 2014 - 07:12 AM
Thank you! I understand few more things about LUA now ^^
Can't wait to finish my other unfinished projects.

Cheers!