Jump to content

Recommended Posts

Posted

Please forgive me if this is posted in the incorrect place, I would have posted to the ComputerCraft Wiki but every time I try to go there I get a bandwidth exceeded message.

I just need a bit of help on a project if anyone is willing to help me. I have seen password protected door tutorials online and have successfully made one, but I want to do something different for the reinforced door to a reactor room and can't figure out how to code it to save my life......which is no surprise given I just started dabbling with ComputerCraft yesterday.

Here is what I want to do....

I want to have a computer console at the door door to my reactor room, you enter a password and a menu comes up with the option to toggle the door open or closed (all the programs I have seen thus far open and then close it after a time limit, I want it open until I toggle it closed with the computer again.) If possible I would even like a status display on the menu of the status of the door either being open of closed. I know this has to be possible but I just can't do it yet and I have been having trouble finding the info I need on Google and other various places.

Any help would be greatly appreciated.

Thank you all in advance.

Posted

I haven't messed with computercraft in a while so I'm going to be a little light on specifics since I don't remember them. it shouldn't be hard to find the info on the wiki once you know what to look for anyway.

making it toggle shouldn't be much harder than timed closing. once the password is accepted you can have it display a little message indicating which button to press to toggle the door, then use the pullevent function (I'm pretty sure you don't need pulleventraw) to wait for a key press. when it gets a key press, check to see if it was the correct key and set the redstone output to whatever it needs to be and use a variable to track the door's status. if the variable is true, then the door's open and it should be closed when the key is pressed. if it's false the door's closed and needs to be opened for example.

you probably also want a second key setup to exit the toggle menu and go back to the password screen. hopefully that helps you out some.

Posted

I haven't messed with computercraft in a while so I'm going to be a little light on specifics since I don't remember them. it shouldn't be hard to find the info on the wiki once you know what to look for anyway.

making it toggle shouldn't be much harder than timed closing. once the password is accepted you can have it display a little message indicating which button to press to toggle the door, then use the pullevent function (I'm pretty sure you don't need pulleventraw) to wait for a key press. when it gets a key press, check to see if it was the correct key and set the redstone output to whatever it needs to be and use a variable to track the door's status. if the variable is true, then the door's open and it should be closed when the key is pressed. if it's false the door's closed and needs to be opened for example.

you probably also want a second key setup to exit the toggle menu and go back to the password screen. hopefully that helps you out some.

Thanks for the tip. I will look into this. When I started working on this I thought that I would find the code for this somewhere that I could study and adapt to my needs but apparently I am either the first person that wants to do this or people are keeping it a closely guarded secret. hehe

As I said in my post, I am brand new at working with lua and learn the most for seeing code examples...the wiki page on events I found is sadly weak in this area but I will keep looking.

At any rate, thank you for the info, I appreciate it and will put it to the best use I can.

Posted

OK...so using what I have learned here and there over the past three days I have cobbled together a program that runs....but does not work. It shows my menu but when I input anything on the keyboard I get the error message for entering an invalid option. Would someone mind looking over my code and see if they can spot my rookie mistake please?

doorpass = "whatever"

pcall(main)

function main()

term.clear()

term.setCursorPos(1,1)

print(".:Reactor Access Panel:.")

print("[1] Open Hatch")

print("[2] Close Hatch")

print("[3] Exit")

a, x = os.pullEvent()

if a == "key" then

if x == 49 then

pcall(doorOpen)

else

if x == 50 then

pcall(doorClose)

else

if x == 51 then

pcall(exit)

else

print("Input Error")

sleep(2)

pcall(main)

end

end

end

end

end

function doorOpen()

term.clear()

term.setCursorPos(1,1)

print(".:Reactor Access Panel:.")

print("!!Password Required for Reactor Access!!")

write("Input Password: ")

password = read("*")

if password == doorpass then

print("Password Correct")

print("Opening Hatch...")

sleep(1)

rs.setOutput("right", true)

pcall(main)

else

print("Invalid Password!")

sleep(2)

pcall(main)

end

end

function doorClose()

term.clear()

term.setCursorPos(1,1)

print("Closing Hatch...")

rs.setOutput("right", false)

sleep(2)

pcall(main)

end

function exit()

shell.exit()

end

Posted

sounds like you may not be getting the values you are expecting for x. put in a print statement after the if statement to determine that the event is a "key" event and have it print out the value of x. something like this:

print("key pressed, value is: ")

println(x)

I totally forgot the string concatenation operator in lua, so I just made it two lines >_>

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...