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

Wireless Comtrolling Of Computers (ComputerCraft 1.53)

Started by MRWOFFLE, 10 July 2013 - 10:54 AM
MRWOFFLE #1
Posted 10 July 2013 - 12:54 PM
I recently joined a faction on a server who had trouble making a program that could write something on a computer. I was the only ône with bare minimal knowledge on it. So I started making password protection, auto buildcraft engine shutoffs, etc. but now they know about the wireless modems, and they asked me to research it.

I can't figure this out at all, I need some help. How does these modems work how do you get a connection between multiple computers and a major thing is that we want to be able to access other computer from one computer that can see everything on all computers, and maybe even something where I can activate a door or TNT cannon from that one computer. Please respond of what this is capable of and if I can make these things, and some programming would help….
Lyqyd #2
Posted 10 July 2013 - 01:39 PM
Split into new topic.

Check out the Wiki, specifically the modems page. You might also look through the Tutorials section to see if there's anything helpful in there. Some of the stuff you're asking about is fairly complex. Are you wanting to code all of it yourself, or are you also interested in using complete programs other people have made?
apemanzilla #3
Posted 10 July 2013 - 01:57 PM
Wireless modems let computers "talk" to each other via the rednet API. There's a bunch of stuff about it on the forums and wiki, but I'll give a rundown of the basic commands.
rednet.open(side) - Activates the modem on the specified side. To use most other functions, you'll need to do this first!
rednet.send(id, data) - Sends the data (Most forms of variables are accepted) to the computer whose id matches the one specified. Running "id" on a computer will show you the id. Note that th receiving computer must have an active rednet connection in range, and must also be pulling a rednet event or waiting on rednet.receive.
rednet.receive(timeout) - Waits for a rednet broadcast, announce or standard message, or until the timeout is hit. Returns sender id, message, and distance to sender, in that order. If timeout is not supplied there is no timeout.
rednet.broadcast(data) - Broadcasts data to all listening computers.

That should be enough to set up a basic control system. Here's an example:

allowedcomp = 0 --Replace 0 with the id of the sender - this is to prevent anyone from sending the messages.
rs.setOutput("back", false) --Reset redstone in case it was on before
while true do
  local id,message = rednet.receive()
  if id == allowedcomp then
    --Do stuff based on message
    --Here's an example, activates rear redstone or deactivates it
    if message == "backrson" then
      rs.setOutput("back",true)
    end
    if message == "backrsoff" then
      rs.setOutput("back", false
    end
  end
end
If you send the string "backrson" or "backrsoff" from the computer with the id in allowedcomp, it will enable/disable redstone. This could be used to make a simple engine toggle, or remote light switch. Just remember that the range on rednet isn't incredibly good, about 64 blocks at sea level, and if it's storming, that drops to a mere 16 blocks.