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

multiple monitors via wired network cables

Started by ItsFlo, 15 February 2016 - 08:07 PM
ItsFlo #1
Posted 15 February 2016 - 09:07 PM
Hi,
I wanted to make a lift with an advanced monitor on each floor. They would all show the same thing so I connected them via the wired network.
To make coding easier I made a table with the monitor names and functions to call their methods.


1  m = peripheral.wrap("top")
2  local monitors = {"monitor_1","monitor_2",...}
3  
4  function clear()
5	  for i=1,#monitors+1 do
6		  m.callRemote(monitors[i],"clear")
7	  end
8  end
9  function pos(x,y)
10	 for i=1,#monitors+1 do
11		 m.callRemote(monitors[i],"setCursorPos",x,y)
12	 end
13 end
14 function col(c)
15	 for i=1,#monitors+1 do
16		 m.callRemote(monitors[i],"setBackgroundColor",c)
17	 end
18 end
19 function write(text)
20	 for i=1,#monitors+1 do
21		 m.callRemote(monitors[i],"write",text)
22	 end
23 end


now when I want do call these functions I get the error:
expected string (i.e. in line 6)

when I replace
m.callRemote(monitors[i],"clear")
with
m.callRemote("monitor_1","clear")
it works but I would have to write more :(/>


Do you have any idea what the problem might be?
Edited on 30 August 2016 - 02:30 PM
Bomb Bloke #2
Posted 16 February 2016 - 12:28 AM
for i=1,#monitors+1 do

This loop will repeat x+1 times, where x is the number of monitors you have. On the last iteration, i will exceed your monitor count, monitors will be nil, and callRemote will crash out.

Remove the "+1".
KingofGamesYami #3
Posted 16 February 2016 - 12:29 AM
Remove the +1. monitors[ #monitors + 1 ] is going to be nil.

Edit: Ninja'd
Edited on 15 February 2016 - 11:29 PM
ItsFlo #4
Posted 17 February 2016 - 12:55 PM
Ooh, off course
Thank you very much

I feel really dumb right now for not noticing that :rolleyes:/>