Edited by coolmark1995, 30 August 2014 - 02:04 AM.
Computercraft Rednet/Redstone Signal
#1
Posted 30 August 2014 - 02:01 AM
#2
Posted 30 August 2014 - 02:44 AM
local pass = "mypassword"
term.clear()
term.setCursorPos(1,1)
write("Enter Password: ")
local input = read("*")
if input == pass then
--do stuff
else
--do bad stuff
end
A basic rundown of this is that i'm setting a password at the top, in this case mypassword and then i print onto the screen for them to enter a password, and if what they entered is mypassword then do stuff. If what they inputted is not mypassword then do bad stuff.Now if you're wanting to integrate that with redstone and rednet then i would look at their respective APIs so that you can attempt to get a grasp on them. Redstone. Rednet.
NOTE: For anything saying side, you need to set that to "left", "right","back", "front","top" or "bottom" each one coresponding to a side of the computer seen when facing the screen of the computer.
Now a basic program for using rednet would be
--# On the receiving computer, you're going to have to start this first.
rednet.open(side that the wireless modem is on) --# THIS MUST BE DONE WHENEVER YOU'RE USING MODEMS.
--# It allows the wireless modem attached to the computer to be used to grab messages.
local senderid,msg = rednet.receive() --#This will look for a rednet message and will continue until it gets one
print(senderid.." messaged you: "..msg)
--# On the sending computer, run this second
rednet.open(Side that the wireless modem is on)
rednet.broadcast("hello") --# This will send the message hello to any computer, now if you know the ID of the receiving computer you could do rednet.sent(id,message)
--# However for the demonstrations this will suffice
--# When you send the message with rednet.broadcast and the other computer receives it, it will print out [id you sent from] messaged you: hello
Now for redstone the basic functions in that are
rs.setOutput(side,true) -- this turns on the redstone on the side you choose. redstone.setOutput(side,false) -- the exact same as the one above, however it turns it off.
Now putting those together you could do
local pass = "mypassword"
term.clear()
term.setCursorPos(1,1)
write("Enter Password: ")
local input = read("*")
if input == pass then
rs.setOutput("back",true) -- sets the output in the back on
rednet.open("left") --opens the wireless modem on the left to use it.
rednet.broadcast("i opened it!") -- sends to any computer receiving rednet messages
else
print("Oh no wrong password")
end
Now this isn't good for more than one try. Now if you need a more in depth look into these i'd be happy to help you, however you only wanted a push in the right direction.Mind you this code isn't safe as anyone who has access to your computer can edit the program and get the password easily, however i'll leave the way to use the password up to you.
Edited by Dragon53535, 30 August 2014 - 02:48 AM.
#3
Posted 30 August 2014 - 02:56 AM
Dragon53535, on 30 August 2014 - 02:44 AM, said:
local pass = "mypassword"
term.clear()
term.setCursorPos(1,1)
write("Enter Password: ")
local input = read("*")
if input == pass then
--do stuff
else
--do bad stuff
end
A basic rundown of this is that i'm setting a password at the top, in this case mypassword and then i print onto the screen for them to enter a password, and if what they entered is mypassword then do stuff. If what they inputted is not mypassword then do bad stuff.Now if you're wanting to integrate that with redstone and rednet then i would look at their respective APIs so that you can attempt to get a grasp on them. Redstone. Rednet.
NOTE: For anything saying side, you need to set that to "left", "right","back", "front","top" or "bottom" each one coresponding to a side of the computer seen when facing the screen of the computer.
Now a basic program for using rednet would be
--# On the receiving computer, you're going to have to start this first.
rednet.open(side that the wireless modem is on) --# THIS MUST BE DONE WHENEVER YOU'RE USING MODEMS.
--# It allows the wireless modem attached to the computer to be used to grab messages.
local senderid,msg = rednet.receive() --#This will look for a rednet message and will continue until it gets one
print(senderid.." messaged you: "..msg)
--# On the sending computer, run this second
rednet.open(Side that the wireless modem is on)
rednet.broadcast("hello") --# This will send the message hello to any computer, now if you know the ID of the receiving computer you could do rednet.sent(id,message)
--# However for the demonstrations this will suffice
--# When you send the message with rednet.broadcast and the other computer receives it, it will print out [id you sent from] messaged you: hello
Now for redstone the basic functions in that are
rs.setOutput(side,true) -- this turns on the redstone on the side you choose. redstone.setOutput(side,false) -- the exact same as the one above, however it turns it off.
Now putting those together you could do
local pass = "mypassword"
term.clear()
term.setCursorPos(1,1)
write("Enter Password: ")
local input = read("*")
if input == pass then
rs.setOutput("back",true) -- sets the output in the back on
rednet.open("left") --opens the wireless modem on the left to use it.
rednet.broadcast("i opened it!") -- sends to any computer receiving rednet messages
else
print("Oh no wrong password")
end
Now this isn't good for more than one try. Now if you need a more in depth look into these i'd be happy to help you, however you only wanted a push in the right direction.Mind you this code isn't safe as anyone who has access to your computer can edit the program and get the password easily, however i'll leave the way to use the password up to you.
#4
Posted 30 August 2014 - 05:25 AM
rednet.open( "top" ) --#open rednet while true do local pass = read( "*" ) --#read user input if pass == "hello" then --#check input --#correct password rs.setOutput( "back", true ) --#toggle redstone on sleep( 1 ) --#wait for a second rs.setOutput( "back", false ) --#toggle redstone off rednet.broadcast( "opened" ) --#send message else --#incorrect password print( "wrong!" ) end end
while true do
local id, message = rednet.receive() --#get message
if message == "opened" then --#message is correct
print( 'door opened' ) --#the door has opened
end
end
#5
Posted 30 August 2014 - 07:01 PM
KingofGamesYami, on 30 August 2014 - 05:25 AM, said:
rednet.open( "top" ) --#open rednet while true do local pass = read( "*" ) --#read user input if pass == "hello" then --#check input --#correct password rs.setOutput( "back", true ) --#toggle redstone on sleep( 1 ) --#wait for a second rs.setOutput( "back", false ) --#toggle redstone off rednet.broadcast( "opened" ) --#send message else --#incorrect password print( "wrong!" ) end end
while true do local id, message = rednet.receive() --#get message if message == "opened" then --#message is correct print( 'door opened' ) --#the door has opened end end
Edited by coolmark1995, 30 August 2014 - 07:30 PM.
#6
Posted 30 August 2014 - 11:06 PM
#8
Posted 31 August 2014 - 03:48 AM
Edited by Dragon53535, 31 August 2014 - 03:48 AM.
#9
Posted 31 August 2014 - 04:46 PM
#10
Posted 31 August 2014 - 04:55 PM
#11
Posted 31 August 2014 - 05:55 PM
#12
Posted 31 August 2014 - 07:14 PM
rednet.open( "top" ) --#open rednet
while true do
local pass = read( "*" ) --#read user input
if string.lower( pass ) == "hello" then --#check input
print( "correct!" )
rs.setOutput( "back", true ) --#toggle redstone on
sleep( 1 ) --#wait for a second
rs.setOutput( "back", false ) --#toggle redstone off
rednet.broadcast( "opened" ) --#send message
else
--#incorrect password
print( "wrong!" )
end
end
Now test it and see if it prints "correct!", I added so you can type HelLo, hEllO etc. If you don't want that then remove string.lowerAlso, did you have caps lock disabled when you used KingOfGamesYamis code?
#13
Posted 31 August 2014 - 07:22 PM
TheOddByte, on 31 August 2014 - 07:14 PM, said:
rednet.open( "top" ) --#open rednet while true do local pass = read( "*" ) --#read user input if string.lower( pass ) == "hello" then --#check input print( "correct!" ) rs.setOutput( "back", true ) --#toggle redstone on sleep( 1 ) --#wait for a second rs.setOutput( "back", false ) --#toggle redstone off rednet.broadcast( "opened" ) --#send message else --#incorrect password print( "wrong!" ) end endNow test it and see if it prints "correct!", I added so you can type HelLo, hEllO etc. If you don't want that then remove string.lower
Also, did you have caps lock disabled when you used KingOfGamesYamis code?
#14
Posted 31 August 2014 - 08:09 PM
rs.setOutput ("back", true)
Does that do anything?
Edited by flaghacker, 31 August 2014 - 08:10 PM.
#15
Posted 31 August 2014 - 08:12 PM
It needs to be directly behind the computer.
2 user(s) are reading this topic
0 members, 2 guests, 0 anonymous users











