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

Computercraft Rednet/Redstone Signal

Started by coolmark1995, 30 August 2014 - 01:01 AM
coolmark1995 #1
Posted 30 August 2014 - 03:01 AM
Hello so I was wondering how I can make a computer secure with password login to emit a power signal to redstone setup and when its on emit a message to a server computer to let you know its working and what computer id it is. I don't want it made for my I just need code ideas as well as how to make a red stone emit timer for each one.
Edited on 30 August 2014 - 01:04 AM
Dragon53535 #2
Posted 30 August 2014 - 03:44 AM
I'm afraid you might have to rephrase that. You're wanting a lock system that if the password you enter is correct it sends a rednet signal to another computer? or where it sends a redstone signal to a door? OR are you having it do both however logging when someone used your lock on a second computer? This information is a slight bit needed, however if you're wanting to make a simple lock then there's plenty of them on this forum, and you could look around and find some to base yours around. However an easy way and primitive would be

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 on 30 August 2014 - 01:48 AM
coolmark1995 #3
Posted 30 August 2014 - 03:56 AM
I'm afraid you might have to rephrase that. You're wanting a lock system that if the password you enter is correct it sends a rednet signal to another computer? or where it sends a redstone signal to a door? OR are you having it do both however logging when someone used your lock on a second computer? This information is a slight bit needed, however if you're wanting to make a simple lock then there's plenty of them on this forum, and you could look around and find some to base yours around. However an easy way and primitive would be

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.
okay so what I am trying to do is have a redstone signal activate with ciomputercraft after you enter password on computer then have that computer explain or leave a message on another computer to tell you its operating/on
KingofGamesYami #4
Posted 30 August 2014 - 06: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
coolmark1995 #5
Posted 30 August 2014 - 08:01 PM

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
I have tried your script but my problem is your code when I enter hello it does not work it just asks me to re enter password why is this? and make computer recieve computer id with message?
Edited on 30 August 2014 - 06:30 PM
Dragon53535 #6
Posted 31 August 2014 - 12:06 AM
When you enter the password does it wait for a second and then ask again?
coolmark1995 #7
Posted 31 August 2014 - 04:36 AM
When you enter the password does it wait for a second and then ask again?
no it just asks again right away
Dragon53535 #8
Posted 31 August 2014 - 04:48 AM
Does it say wrong? Make sure you're typing hello, and not Hello or hEllo
Edited on 31 August 2014 - 02:48 AM
coolmark1995 #9
Posted 31 August 2014 - 05:46 PM
im typing hello all it does is ask for password doesn't send a redstone output
Dragon53535 #10
Posted 31 August 2014 - 05:55 PM
Is your redstone in the back? because my test world is working correctly with it.
Lyqyd #11
Posted 31 August 2014 - 06:55 PM
Are you on a server using MCPC+/Cauldron?
TheOddByte #12
Posted 31 August 2014 - 08:14 PM
I modified KingOfGamesYamis code, even though it is correct.

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.lower
Also, did you have caps lock disabled when you used KingOfGamesYamis code?
coolmark1995 #13
Posted 31 August 2014 - 08:22 PM
I modified KingOfGamesYamis code, even though it is correct.

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.lower
Also, did you have caps lock disabled when you used KingOfGamesYamis code?
its just not out putting read stone and my pass and all is correct I am using 1.7.2 computercraft
flaghacker #14
Posted 31 August 2014 - 09:09 PM
Type lua, then this code:

rs.setOutput ("back", true)

Does that do anything?
Edited on 31 August 2014 - 07:10 PM
TheOddByte #15
Posted 31 August 2014 - 09:12 PM
Can you post a screenshot of how you've set it up? Like show us where you put the redstone.
It needs to be directly behind the computer.