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

Monitors In A Computer (With Ccable)

Started by Lux, 26 August 2013 - 12:32 AM
Lux #1
Posted 26 August 2013 - 02:32 AM
Hello! I did a thread with my problem before. I want see the same program in the four monitors. Please read this http://www.computercraft.info/forums2/index.php?/topic/14831-multiple-monitors/ . I don't know how can I do this, so please tell me the edited code. I'm newbie in LUA and CC. Thanks!
theoriginalbit #2
Posted 26 August 2013 - 02:44 AM
Just as Last1Here and Kingdaro showed in that thread, we can use tables and a loop to get this to work. Something like the following example…


local targets = {
  "back:red";
  "back:green";
  "back:blue";
  "back:cyan";
  --# etc, etc, etc
}

local function doMonitor( device )
  --# redirect to the target
  term.redirect( device )

  --# your code goes here, making sure to ONLY use term. calls instead off direct calls on the monitor
  --# avoid infinite loops, this really should just be the render code for the monitors

  --# restore the terminal
  term.restore()
end

--# if you want to do anything like text scale do it here
for index,name in ipairs(targets) do
  peripheral.call(name, "setTextScale", 0.5)
end

--# infinite loops goes here
while true do
  --# process user input and such here

  --# loop through the targets to draw to them
  for index,name in ipairs(targets) do
	--# wrap the target and supply it to the doMonitor function
	doMonitor( peripheral.wrap(name) )
  end
end