LyteWing Posted August 24, 2012 Posted August 24, 2012 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 properly. It is supposed to show me a menu of three option (one option to open a door, one option to close a door, and one to exit the program). 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? Sometimes a fresh set of eyes can really make all the difference. 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
RPGpro Posted August 24, 2012 Posted August 24, 2012 I'm not 100% sure but I think there's a problem on line 6 of the doorOpen function "password = read("*")" try "password = io.read()" instead. As for your main problem, personally I'd write it differently as I can't find any info about Lua's keyboard input codes besides the fact they're not standard ascii ones. Try something like: function main() term.clear() term.setCursorPos(1,1) print(".:Reactor Access Panel:.") print("[1] Open Hatch") print("[2] Close Hatch") print("[3] Exit") x = io.read(1) if x == "1" then pcall(doorOpen) else if x == "2" then pcall(doorClose) else if x == "3" then pcall(exit) else print("Input Error") sleep(2) pcall(main) end end end end
LyteWing Posted August 24, 2012 Author Posted August 24, 2012 I'm not 100% sure but I think there's a problem on line 6 of the doorOpen function "password = read("*")" try "password = io.read()" instead. As for your main problem, personally I'd write it differently as I can't find any info about Lua's keyboard input codes besides the fact they're not standard ascii ones. Try something like: function main() term.clear() term.setCursorPos(1,1) print(".:Reactor Access Panel:.") print("[1] Open Hatch") print("[2] Close Hatch") print("[3] Exit") x = io.read(1) if x == "1" then pcall(doorOpen) else if x == "2" then pcall(doorClose) else if x == "3" then pcall(exit) else print("Input Error") sleep(2) pcall(main) end end end end Thank you for the input...I just went to try this on the server I was working on and the nuclear reactor I was writing the program for had blown up and took the computer I was writing it on with it...should have made a backup! hehehe Oh well..I will rewrite it and use your adjustments and let you know how it came out. Obviously at this point I should have been less concerned with opening and closing the door and more concerned with how much uranium my friend was shoving into the reactor. hehe
DoctorCube Posted August 24, 2012 Posted August 24, 2012 You could probably use CCSensors to read your Nuke's temperature and do an auto-off too. :)
RPGpro Posted August 24, 2012 Posted August 24, 2012 You could probably use CCSensors to read your Nuke's temperature and do an auto-off too. they're a bit buggy on servers though... using an MFFS to detect, control and respond to the reactor temperature change would be good though
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now