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

Monitor-Terminal dupe over rednet?

Started by Xenthera, 23 May 2013 - 02:37 PM
Xenthera #1
Posted 23 May 2013 - 04:37 PM
Looking to use this code from Computercraftfan


local nativeTerm = term.native or term
local function invoke(sMethod, ...)
nativeTerm[sMethod](...)
for k,sSide in pairs(redstone.getSides()) do
  if peripheral.isPresent(sSide) and peripheral.getType(sSide) == "monitor" then
   peripheral.call(sSide, sMethod, ...)
  end
end
end
term.write = function(text) invoke("write", text) end
term.scroll = function(n) invoke("scroll", n) end
term.setCursorPos = function(x, y) invoke("setCursorPos", x, y) end
term.setCursorBlink = function(:o/>/>/> invoke("setCursorBlink", :o/>/>/> end
term.clear = function() invoke("clear") end
term.clearLine = function() invoke("clearLine") end
nativeTerm.clear()
nativeTerm.setCursorPos(1, 1)
print(os.version())

It copies the terminal onto a monitor. I need to do something similar but over rednet, so I can have multiple monitors that aren't connected to a single computer. Any help?
W00dyR #2
Posted 23 May 2013 - 04:49 PM
You will always have a computer connected to a monitor, because a monitor can't receive rednet messages, a computer can.
Xenthera #3
Posted 23 May 2013 - 04:55 PM
You will always have a computer connected to a monitor, because a monitor can't receive rednet messages, a computer can.

I know. I will send the rednet message to a computer attached to a monitor.
Xenthera #4
Posted 23 May 2013 - 05:32 PM
Nevermind, if you want to do something right, do it yourself. I figured it out.
SuicidalSTDz #5
Posted 24 May 2013 - 07:37 AM
Nevermind, if you want to do something right, do it yourself
That is not always the case. You obviously didn't know how to solve this problem by yourself, so you came to us. You should have also exhausted all possible solutions before doing so, since you obviously had a hidden solution not yet exhausted.
KaoS #6
Posted 24 May 2013 - 10:03 AM
I disagree, asking for help is fine at any stage… Xenthera if you are still interested I would like to help
W00dyR #7
Posted 24 May 2013 - 10:48 AM
Nevermind, if you want to do something right, do it yourself. I figured it out.

Can you post/PM how you've done it? I'm very interested! :)/>
BigSHinyToys #8
Posted 24 May 2013 - 11:50 AM
Nevermind, if you want to do something right, do it yourself. I figured it out.

Can you post/PM how you've done it? I'm very interested! :)/>

The theory is simple use term.redirect to install your custom "term" that has a function that sends every call example "write" or "setCursorPos" to the other computer if a response is needed you have to make the receive computer send it back this is what programs like nsh from lyqyd do. On the other hand you can make a false screen with a table and have all term calls go change this table then send this table to the other like a image tat is then draw at the reviver. the other option is to Optimist the system by only sending stuff and not waiting for getCursorPos or getSize . You can then store all the term calls in a table package that up and send it in one rednet message reducing the rednet message count from about ~300 to 30 and you end up with something like this.
client: http://pastebin.com/qjFPSEvd
server: http://pastebin.com/QUr1Cj4e
Not exactly what you were looking for but has all the bits needed it with a little manipulation.
Xenthera #9
Posted 24 May 2013 - 06:09 PM
Thanks for all the responses, I didn't think of the solution until after I posted this.

It was similar to BigSHinyToys' way. Except it sends the 300+ rednet messages and lags out when using 3+ receiving computers. None-the-less it works for what I need.

In the original code I looked for where it was calling the local monitor "peripheral.call(sSide,sMethod,…)"


local nativeTerm = term.native or term
local function invoke(sMethod, ...)
nativeTerm[sMethod](...)
for k,sSide in pairs(redstone.getSides()) do
  if peripheral.isPresent(sSide) and peripheral.getType(sSide) == "monitor" then

--HERE
   peripheral.call(sSide, sMethod, ...)
  

end
end
end
term.write = function(text) invoke("write", text) end
term.scroll = function(n) invoke("scroll", n) end
term.setCursorPos = function(x, y) invoke("setCursorPos", x, y) end
term.setCursorBlink = function() invoke("setCursorBlink")
term.clear = function() invoke("clear") end
term.clearLine = function() invoke("clearLine") end
nativeTerm.clear()
nativeTerm.setCursorPos(1, 1)
print(os.version())

Then I added

send = {sMethod,...}
encryptedSend = texutils.serialize(send)
rednet.broadcast(encryptedSend)


In the end the sending computer's code looked like this


local nativeTerm = term.native or term
local function invoke(sMethod, ...)
nativeTerm[sMethod](...)
for k,sSide in pairs(redstone.getSides()) do
  if peripheral.isPresent(sSide) and peripheral.getType(sSide) == "monitor" then


   peripheral.call(sSide, sMethod, ...)
  
send = {sMethod,...}
encryptedSend = textutils.serialize(send)
rednet.broadcast(encryptedSend)

end
end
end
term.write = function(text) invoke("write", text) end
term.scroll = function(n) invoke("scroll", n) end
term.setCursorPos = function(x, y) invoke("setCursorPos", x, y) end
term.setCursorBlink = function() invoke("setCursorBlink")
term.clear = function() invoke("clear") end
term.clearLine = function() invoke("clearLine") end
nativeTerm.clear()
nativeTerm.setCursorPos(1, 1)
print(os.version())

Receiving computer code:


side = "right"
m = peripheral.wrap(side)
m.setTextScale(.7)
rednet.open("left")
while true do
  event, id, message = os.pullEvent("rednet_message")
  unmessage = textutils.unserialize(message)

   if #unmessage == 1 then
   peripheral.call(side,unmessage[1])
   elseif #unmessage == 2 then
   peripheral.call(side,unmessage[1],unmessage[2])
   elseif #unmessage == 3 then
   peripheral.call(side,unmessage[1],unmessage[2],unmessage[3])
   end
end

Which just gets the sent table, 'decodes' it, then checks for the amount of arguments which I send to the connected monitor.
Thefdjurt #10
Posted 25 May 2013 - 01:08 PM

local nativeTerm = term.native or term
local function invoke(sMethod, ...)
nativeTerm[sMethod](...)
for k,sSide in pairs(redstone.getSides()) do
  if peripheral.isPresent(sSide) and peripheral.getType(sSide) == "monitor" then
   peripheral.call(sSide, sMethod, ...)
  end
end
end
term.write = function(text) invoke("write", text) end
term.scroll = function(n) invoke("scroll", n) end
term.setCursorPos = function(x, y) invoke("setCursorPos", x, y) end
term.setCursorBlink = function(:o/>/>/>/>/>/>/>/> invoke("setCursorBlink", :o/>/>/>/>/>/>/>/> end
term.clear = function() invoke("clear") end
term.clearLine = function() invoke("clearLine") end
nativeTerm.clear()
nativeTerm.setCursorPos(1, 1)
print(os.version())

It copies the terminal onto a monitor. I need to do something similar but over rednet, so I can have multiple monitors that aren't connected to a single computer. Any help?
What do you mean by that.Receive a rednet message, then display the terminal on a monitor?Or receive a rednet message and then display the terminal on another computer?
Xenthera #11
Posted 25 May 2013 - 01:47 PM

local nativeTerm = term.native or term
local function invoke(sMethod, ...)
nativeTerm[sMethod](...)
for k,sSide in pairs(redstone.getSides()) do
  if peripheral.isPresent(sSide) and peripheral.getType(sSide) == "monitor" then
   peripheral.call(sSide, sMethod, ...)
  end
end
end
term.write = function(text) invoke("write", text) end
term.scroll = function(n) invoke("scroll", n) end
term.setCursorPos = function(x, y) invoke("setCursorPos", x, y) end
term.setCursorBlink = function(:o/>/>/>/>/>/>/>/>/> invoke("setCursorBlink", :o/>/>/>/>/>/>/>/>/> end
term.clear = function() invoke("clear") end
term.clearLine = function() invoke("clearLine") end
nativeTerm.clear()
nativeTerm.setCursorPos(1, 1)
print(os.version())

It copies the terminal onto a monitor. I need to do something similar but over rednet, so I can have multiple monitors that aren't connected to a single computer. Any help?
What do you mean by that.Receive a rednet message, then display the terminal on a monitor?Or receive a rednet message and then display the terminal on another computer?


If you look right above your post, I already explained everything. I wanted to dupe the terminal from one computer, onto the monitors of other computers over rednet. Already figured it out though, I even explain how.