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 />
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
You could solve this problem just with redstone - instead of wiring both computers to the door directly, connect both to an inverter (a block with a torch), and connect that torch to the door. Then reverse your outputs at the computers - so they send "on" to open and "off" to close - and you'd be set!
You could solve this problem just with redstone - instead of wiring both computers to the door directly, connect both to an inverter (a block with a torch), and connect that torch to the door. Then reverse your outputs at the computers - so they send "on" to open and "off" to close - and you'd be set!
Mm, Never used Inverters before... will try it out now and check />
You could also use rednet to communicate between them. have one computer wait for an event, and if the event is a rednet signal from the other computer, have it do whatever the other computer tells it. If it's a key touch, have it look at input
The key press event happens before the char event, so if you do that then the computer will still catch everything you type, even that first key that triggers the event.
I would say to hook both of them up with a wireless modem each, and when the correct passcode is entered, whichever computer is use, it sends a rednet messeage to the other (also when the incorrect passcode is entered, but a different message). When the other receives the message, it disables it's lock for a limited time, say 3-5 seconds.
Also, about making computers unbreakable, you could label them, which makes them almost permanent. When they get broken, they don't turn back into a generic computer, rather, they stay as the same computer, so you could also move them if you need to.
I would say take a step back, you dont seem to know and redstone, considering inverter is the first thing you learn.
I recommend you dable with redstone first, then move to computercraft programming...
Programming and dealing with redstone logic is 2 different things. Why would one be a pre-req for the other??
If you use RP2 just use a nor gate, it does the same thing as an inverter but takes up less space.
Personally I would just use rednet and events...
It will help him in the future, this is Minecraft non the less... if we were doing windows programming it be different but considering redstone is going to be a major aspect, I recommend learning the basics of Minecraft before advancing towards a complicated mod.
Not so much, if you're good enough at coding you can use the computer itself to function as your logic gates etc.. Thus why I said I would just use rednet and events to accomplish this task.
The most I do with redstone in any of my devices that I use the CC Computer with is pretty much just using redstone dust or the RP red alloy cables to connect the computer to what it is controlling and the computer does the rest of the work.