I just started learning LUA programming and making programs now and then, also going through other's programs to check them out. My friend asked me to make a program to open a gate if the correct password is entered. If the password is incorrectly put into the computer, it will then sound an alarm until a master password is inputed, or if tesla option is set to yes, it will set the tesla coil off and kill you xD.
Anyway my question is: Is it possible to connect two computers together as one? Because for this gate, one computer on each side needs to be placed. But as you can see in the code, the code activates the redstone output, only when the password is entered, it then puts it off. But now both computers make the redstone.output true so therefor when the password is entered into one of the computers, it does nothing - because the redstone wire is still on from the other. If this makes sense? :?
Also, if there is anyway to make my code shorter - feel free to do it and show me so I can learn more of how to shorten it :(/>/>
Code: pastebin or at bottom of post.
Another question: Is it possible to make computers un-breakable? So randoms cant break it and screw it up xD
Spoiler
-- Configuration
-- Strings
-- Passwords
local sBypasspw = "secant"
local sDoorpw = "derp"
local sRedstoneSide = "top"
local sAlarmSide = "left"
local sMasterpw = "borderlands"
local sAlarmInput = ""
local sTeslaSide = "bottom"
local sTesla = "yes"
-- Names
local sVillageName = "derpington"
-- Values
-- Door values
local tDoor = 5
local tBypass = 15
local nWrongTimes = 3
local nWrongCount = 0
-- Do not edit from here
-- Functions
function clearPrint(string, x, y)
if not x or x < 0 then x = 1 end
if not y or y < 0 then y = 1 end
term.clear()
term.setCursorPos(x,y)
print(string)
end
-- if statement
function checkPW(PW)
if PW == sDoorpw then
clearPrint("Password correct! Please proceed - door will close in "..tDoor.." seconds.")
rs.setOutput(sRedstoneSide,false)
sleep(tDoor)
rs.setOutput(sRedstoneSide,true)
clearPrint("Door closed!")
sleep(1.5)
elseif PW == sBypasspw then
clearPrint("System Bypassed. Gate will remain open for "..tBypass.." seconds. Please proceed.")
rs.setOutput(sRedstoneSide,false)
sleep(tBypass)
rs.setOutput(sRedstoneSide,true)
clearPrint("Door closed!")
sleep(1.5)
else
clearPrint("Password incorrect! Please try again")
sleep(1)
nWrongCount = nWrongCount + 1
if nWrongCount == nWrongTimes then
if sTesla == "yes" then
rs.setOutput(sAlarmSide,true)
clearPrint("Alarms Activated!")
sleep(1.8)
rs.setOutput(sTeslaSide,true)
clearPrint("HAHA DIE BITCH!")
sleep(3)
rs.setOutput(sAlarmSide,false)
rs.setOutput(sTeslaSide,false)
nWrongCount = 0 -- resets wrong count
else
while sAlarmInput ~= sMasterpw do
rs.setOutput(sAlarmSide,true) -- activates alarm
clearPrint("Alarms activated! Please enter Master password to de-activate alarms.")
write("Master password: ")
sAlarmInput = read()
end
clearPrint("De-activated alarms...")
sleep(1)
nWrongCount = 0 -- resets wrong count
sAlarmInput = ""
rs.setOutput(sAlarmSide,false) -- deactivates alarm
end
nWrongCount = 0
end -- end if function for wrong times
end
end
while true do
clearPrint("Welcome to "..sVillageName..", user.")
write("Enter password to open gate: ")
rs.setOutput(sRedstoneSide,true)
if checkPW(read()) == sBypasspw then break end
end