Jump to content




multiple monitors, one computer


11 replies to this topic

#1 thetrin777

  • Members
  • 11 posts

Posted 22 December 2014 - 07:13 PM

Hello Computercraft forums! This is my first post so I had to say hi. So. ... hi!

I have done quite a bit of looking around and haven't found what I need. I'm building a combat arena for some pvp type awesomeness. And I want to time the matches, using a large monitor to display the countdown to the players.

Here's the question.

I've got four big monitors (5 tall by 4 wide) built into the walls. Is there some way to make all four display the same thing coming from one central computer?

Any help would be magnificent. Thanks in advance all you gurus out there!

#2 Cozzimoto

  • Members
  • 221 posts
  • LocationDallas, Tx

Posted 23 December 2014 - 02:21 AM

A quick and dirty way of doing it would be wrapping the monitors in a table, create a function for drawing your screen and then looping through your table of monitors and drawing to all the monitors.

I can give you a simple script later if you need one. Currently out and about browsing on my mobile.

#3 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 23 December 2014 - 02:37 AM

I was actually trying to do this earlier, my approach is a little intensive on the processing power though.

Here's what I was attempting:

1 - Find all monitors

2 - Tie a new instance of the program to each monitor

3 - Run all of them in a custom coroutine manager

There are two issues with this: 1 - monitor_touch / mouse_click is a little broken, 2 - math.random.

#4 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 23 December 2014 - 10:52 AM

View PostKingofGamesYami, on 23 December 2014 - 02:37 AM, said:

-snip-
this solution is overkill.

The OP stated that they have four monitors all of the same size, the simplest solution would be to define a function which performs the action on all the monitors
--# all the monitors to draw on
local monitors = {
  peripheral.wrap( "monitor_0" ),
  peripheral.wrap( "monitor_1" ),
  peripheral.wrap( "monitor_2" ),
  peripheral.wrap( "monitor_3" ),
}

local function clear()
  for _,mon in pairs( monitors ) do
    mon.clear()
  end
end

local function write( ... )
  for _,mon in pairs( monitors ) do
    mon.write( ... )
  end
end


#5 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 23 December 2014 - 12:06 PM

Wasn't there another post here before...?

I'd make a redirect object:

local monitors = {peripheral.find("monitor")}  -- "find" needs CC 1.6 or later

local multiTerm = {}
for funcName,_ in pairs(monitors[1]) do
	multiTerm[funcName] = function(...)
		for i=1,#monitors-1 do monitors[i][funcName](unpack(arg)) end
		return monitors[#monitors][funcName](unpack(arg))
	end
end
term.redirect(multiTerm)

term.clear()
term.setCursorPos(1,1)
print("Hello world!")


#6 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 23 December 2014 - 04:33 PM

To prevent unhelpful/inaccurate/incorrect information being posted again, the correct way to place multiple monitors of a given type in a table is:

local monitors = {peripheral.find("monitor")}

This method gives you an easily iterable list, and ensures that only monitor-type peripherals are wrapped. A couple of posts by Cozzimoto were removed due to problematic and/or confusing code.

#7 thetrin777

  • Members
  • 11 posts

Posted 23 December 2014 - 09:52 PM

Thanks to everyone for getting back to me so fast. :)

Something I forgot to mention I needed help with...

The way this arena is built, I need to figure how to physically link these monitors to the computer. Like, would rednet cabling work? I dont think WR-CBE will work. And if it does i cant figure it out lol.

Anyway, sorry if this kinda throws a wrench in this... ill keep working at it but all help is yet again appreciated.

BTW if some screenshots would clarify anything i can get some.

#8 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 23 December 2014 - 10:33 PM

The best option is ComputerCraft's networking cables, which much of the code suggested above assumes you are using.

#9 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 24 December 2014 - 06:02 AM

The idea is that you slap a wired modem on the computer plus each monitor, then use the networking cable to link them all together. Once that's done, use (right-click) each monitor's modem to "connect" them, then try running eg the code snippet I posted above.

#10 thetrin777

  • Members
  • 11 posts

Posted 26 December 2014 - 07:47 PM

View PostBomb Bloke, on 24 December 2014 - 06:02 AM, said:

The idea is that you slap a wired modem on the computer plus each monitor, then use the networking cable to link them all together. Once that's done, use (right-click) each monitor's modem to "connect" them, then try running eg the code snippet I posted above.

I got it all set up and it works once I corrected all my typos. Lol

I'm about to start writing my counter program, but before I do , can you explain this code a little bit,? I'm still really new to lua and though it works I'd like to understand how it works.




#11 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 26 December 2014 - 11:08 PM

Difficult to write an explanation that's anywhere near as short as the code. I'll try to give a basic overview.

The idea is that term - the table that holds all the functions you use to write to the default display - can be replaced by a table of functions that write to a different display (using term.redirect()).

When you wrap an external monitor, you get a table filled with functions that write to that monitor (peripheral.find() offers a way to wrap lots of peripherals of a similar type quickly). This is an example of the sort of table you might redirect term to.

So, the code works by first filling a table with wrapped monitor tables, then generating a new table containing one function for every function which exists in those monitor tables (using an iterator for loop) - these new functions run the equivalent functions on all wrapped monitors when you call them, using another for loop.

The end result is a table that you can redirect the terminal to that'll result in all subsequent screen writes being performed on all your attached monitors.

You could, if you wanted, use this table without redirecting to it. For example, if you skipped out on the term.redirect(multiTerm) line, you could instead use commands like multiTerm.setCursorPos(1,1) or multiTerm.write("whatever") to deal with the collection of monitors.

The benefit of redirecting is that certain commands - such as print(), which handles display scrolling and word-wrap for you, as well as all the commands in the paintutils API - will only work on the current terminal.

#12 thetrin777

  • Members
  • 11 posts

Posted 26 December 2014 - 11:41 PM

OK its a little clearer. Thank you very much! Guess all thats left to do now is incorporate my countdown timer into this.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users