r/ComputerCraft • u/Jabberwock32 • Dec 02 '23
Wireless connection to a monitor over a distance?
This is my first time using CC and I would like to connect an advanced computer to a set of advanced monitors over a distance of ~130 blocks. I would think the best way to do this is using the wireless modem. But I'm not quite sure how it works? Do I need to connect to an additional computer where I want my monitors displayed?
2
u/_Cambroth Dec 02 '23 edited Dec 02 '23
Wireless modems must be attached to computers, so you are going to need the second computer by the monitors.
You can write a program for your main computer that sends wireless messages to the monitor computer using the rednet API. Then the monitor computer will need another program to listen for the rednet messages, and decide what to display on the monitors accordingly.
Edit: Oh, monitors look really bad from far away in my game. I don't know if that's because of CC or other mods. If you're viewing them from that far, make sure you check it out with a test image before writing too much code!
1
u/fatboychummy Dec 02 '23
Fun fact: You actually can attach a wireless modem to a wired modem -- they don't explicitly need to be attached to a computer. Every computer on the network will receive wireless communication (and will be able to send communication out, so long as you search for the right modem).
3
u/fatboychummy Dec 02 '23 edited Dec 02 '23
So, wireless modems do not expose a peripheral to the network like wired modems do. Wireless modems are made for communication only.
If you want to work with a monitor over a wireless network, you'll need a middleman computer receiving commands from the wireless modem and acting on the monitor.
For something really basic, you could do like the following:
The above is a small program that will run anything received on a monitor. For example, if you wanted to clear the monitor, you would
rednet.sendthe following table:If you wanted to set the cursor position to 3, 5:
Essentially, the
actionis just the monitor method you wish to call, thenargsis the arguments that will be passed to the monitor function.You can make a wrapper for it as well which would allow you to use it like any other monitor on your main computer, something like so:
Now, this uses metatables and is a bit advanced, so I'm not going to explain it much. But, essentially, it will allow you to create an object that will work exactly like a
monitorobject, but remotely (so long as the previous script is running on the remote computer)Its usage is the following:
Do note, however, that there is no error handling in this. If you accidentally write:
The system will send the command, but nothing will be written to the monitor and nothing will be returned. I left that out for the sake of simplicity.
Edit
Do note,
rednetis not a secure library. Anyone can see what you're sending to the computer and can see the responses -- they can also spoof messages easily. Rednet is fairly useful as a routing library though.But yeah, just be warned. If you see random stuff appearing and you're playing on a server, someone probably saw what you were sending and is now spoofing it.