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

I need a burglar alarm system!

Started by Amenofisch, 26 October 2017 - 03:14 PM
Amenofisch #1
Posted 26 October 2017 - 05:14 PM
I need a system where i can hava "server" and if i write a password in it it sends via rednet a message to all clients to arm so if someone steps on a pressure plate where the client is connected it sends a message to the server and it activates an alarm until the correct password is entered!


If someone could make this for me! Thank you very much!!!
Dave-ee Jones #2
Posted 27 October 2017 - 04:44 AM
Do you know any Lua programming? If not, then you'll have to learn. If you do know some Lua then we can point you in the right direction for what functions and code blocks you're going to need. We're happy to help you along, but don't expect to be spoon-fed a bunch of working code.

What you're looking for is a generic password lock that constantly checks for a redstone input from a specific side.

Here's an example of the 'read()' function:

local input = read()
if input == "hello" then
  print("Hello to you too!")
end
The 'read()' function waits for user keyboard input and then puts it all in a string, returning it to the 'input' variable, which you can check with if statements, as shown above.

Here's an example of checking a side for redstone input:

--# Sides are 'left','right','top','bottom'
local isLeftOn = rs.getInput("left")
print(isLeftOn) --# Either True or False
If 'isLeftOn' is true, it means that any redstone touching the left side of the computer is glowing/on. If it's false, it's not on.

Here's an example of sending a rednet message:

rednet.open("top") --# Remember to open your modem first
rednet.send(id,"It's ON!")
Easy. ID refers to the computer-you-want-to-send-the-message-to's ID.

Here's an example of a loop (needed to constantly check for redstone input or the 'read' function):

local running = true
while running do
  print("I'm still running!")
  sleep(1)
end
This will print 'I'm still running!' every second on the screen, forever. If you get stuck here, use the keyboard combo 'Ctrl + T' to terminate the program.

If you combine all these you can make the program you want. If you get stuck with Lua syntax you can always Google it (I always do, most of the time I figure out the syntax or error quickly), and if you don't find the answer you can ask here or in the 'Ask a Pro' subforum.

There are MANY examples of password locks all over the forums and elsewhere, so finding a simple one shouldn't be too hard! Good luck!
Edited on 27 October 2017 - 02:45 AM
Luca_S #3
Posted 28 October 2017 - 07:15 AM
In addition here are a few CC Wiki links that might help you(They are a bit more in-depth than what Dave-ee already wrote):

Rednet
Redstone
Print
Read