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

Sending Commands From One Computer To Another

Started by KenJ1989, 26 July 2013 - 06:24 PM
KenJ1989 #1
Posted 26 July 2013 - 08:24 PM
Okay, so I am trying to send a command from one computer, to another using the wireless modem.

When I type in "Lock" on computer #1, I want it to have computer #2 run "shell2" when I go to access it from "startup". "shell2" will have computer #2 say "LOCKED" for any amount of time I choose when putting in the script. But when computer #1 isn't sending a command, I want computer #2 to do it's normal scripting that I have written already.

I've tried messing around with it, but it's gotten me nowhere and I'm hoping someone here can help me.

Much thanks to anyone that helps me complete this script.
Kingdaro #2
Posted 26 July 2013 - 10:49 PM
Post your current script?
KenJ1989 #3
Posted 26 July 2013 - 11:01 PM
Computer#1

Here's my startup file:

Spoilerterm.clear()
rednet.open("left")
write "Please Wait…"
sleep(3)
shell.run("Shell")

Here's my shell file:

Spoiler
pass = "123"
term.clear()
term.setCursorPos(1,2)
write "Welcome User, please Enter Password:"
input = read("*")
if pass == input then
term.clear()
term.setCursorPos(1,1)
write "Door Opening"
rednet.broadcast"Open Door"
sleep(3)
term.clear()
shell.run()
end
term.setCursorPos(1,2)
write "Welcome User, please Enter Password:"
input = read("*")
if input == "Lock" then
term.clear()
term.setCursorPos(1,1)
write "Computer Locked"
rednet.broadcast"Lock"
sleep(100000)
end
term.setCursorPos(1,2)
write "Welcome User, please Enter Password:"
input = read("*")
if input == "Unlock" then
term.clear()
term.setCursorPos(1,1)
write "Computer Unlocked"
rednet.broadcast"Unlock"
sleep(5)
term.clear()
shell.run("startup")
else
term.clear()
term.setCursorPos(1,1)
write "Access Denied"
sleep(2)
term.clear()
end
shell.run("Shell")

Computer#2

Startup file:

Spoilerrednet.open("top")
message = rednet.receive()
if message == ("Lock") then
shell.run("shell2")
else
term.clear()
term.setCursorPos(1, 1)
print("Please Enter Password:")
local input = read("*")
if input == "123" then
print("Access Granted")
term.clear()
shell.run("shell")
sleep(1)
else
print("Access Denied")
sleep(2)
term.clear()
end
end

Shell File:

Spoilerrednet.open("top")
if redstone.getInput("bottom") == true then
os.reboot()
else
term.clear()
term.setCursorPos(1,2)
write "Welcome, OPEN or CLOSE?"
input = read("*")
if input == "CLOSE" then
term.clear()
term.setCursorPos(1,1)
write "Door Closing"
redstone.setOutput("back", true)
sleep(2)
shell.run("shell")
end
if input == "OPEN" then
term.clear()
term.setCursorPos(1,1)
write "Door Opening"
redstone.setOutput("back", false)
sleep(2)
shell.run("shell")
end
if input == "Exit" then
term.clear()
term.setCursorPos(1,1)
write "Exiting"
redstone.setOutput("back", true)
sleep(2)
shell.run("startup")
else
term.clear()
term.setCursorPos(1,1)
write "Please Try Again"
sleep(2)
term.clear()
end
end

Shell2 File:

Spoilerterm.setCursorPos(1,2)
term.clear.()
write "LOCKED"
sleep(100000)
end

Maybe I'm doing something wrong, maybe I'm stupid, ha. I'm new at this.
KenJ1989 #4
Posted 27 July 2013 - 12:54 AM
The issues I am having is when I send the command to computer#2, it doesn't do anything but make it say craftblahblahblah and with a blank screen instead of sening computer#2 to "shell2" so that the computer is bascially locked till I unlock it from computer#1.
KenJ1989 #5
Posted 27 July 2013 - 01:55 AM
The issues I am having is when I send the command to computer#2, it doesn't do anything but make it say craftblahblahblah and with a blank screen instead of sening computer#2 to "shell2" so that the computer is bascially locked till I unlock it from computer#1.

When asking for help, "craftblahblahblah" doesn't adequately describe what is happening. There are people here who are able to help you, but you need to step up the effort in your requests. Coding is about accuracy and specifics. So too should be the information you provide when asking for help.

I explained to you two errors with your code that will prevent you from getting the outcome you're looking for. I am not going to re-write your code for you.

I have no problem with not adding the brackets when I do the write command. It works fine without them. But the other thing, that you are right on and I am working on it. As for the "craftblahblahblah", it's the default caption on the screen when you first put the computer block down and open it.
KenJ1989 #6
Posted 27 July 2013 - 02:43 AM
Alright, I never thought of it that way. I'll give it a shot and hopefully it'll work, thanks.
albrat #7
Posted 27 July 2013 - 05:13 AM
The issues I am having is when I send the command to computer#2, it doesn't do anything but make it say craftblahblahblah and with a blank screen instead of sening computer#2 to "shell2" so that the computer is bascially locked till I unlock it from computer#1.

After reading your coding… You have the startup file (on computer #2) grab "message = rednet.receive()" this will wait for ever untill a rednet message is received. you could make it wait for a set amount of time by adding a time in the brackets. eg. rednet.receive(5) – will wait 5 seconds then move on.

also like mentioned about the () are very important as if you have a lot of actions going off it can skip a item or error the program while running without them. Good syntax helps the parsing program, it will allow your script to run more efficiently and makes it prettier for us to read. lol
Lyqyd #8
Posted 27 July 2013 - 01:00 PM
rednet.receive returns the ID of the sending computer first, not the message. You need to use `id, message = rednet.receive()` instead (look at the startup file of computer 2 specifically, but make sure to fix it everywhere).