Jump to content




Running one program simultainiously on two monitors

peripheral help

3 replies to this topic

#1 em_niss

  • New Members
  • 2 posts

Posted 15 August 2015 - 12:27 AM

I have this problem where I want to have two monitors showing the same program at the same time (because of symetry :) ).
Currently I have the program running on one monitor and I'm currently wraping the monitor like this:
mon = peripheral.wrap("top").
I wonder if there is a way to store two monitors in one variable (in this case mon) so when I call for example mon.write("Hello") both monitors write Hello?

Edited by em_niss, 15 August 2015 - 12:49 AM.


#2 KingofGamesYami

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

Posted 15 August 2015 - 02:12 AM

Well, you can do what you want, but it's rather hackish and usually has some problems.

local mon1, mon2 = peripheral.wrap( "top" ), peripheral.wrap( "left" )

local mon = {} --#make a blank table
for k, v in pairs( mon1 ) do --#iterate through the functions of mon1
  mon[ k ] = function( ... ) --#make a new function that calls both monitors' functions.
    local result = {v( ... )} --#this'll call mon1's function, and store any values returned
    mon2[ k ]( ... ) --#this just calls mon2's function
    return unpack( result ) --#this returns whatever mon1's function would've returned.
  end
end
mon.write( "Hello" )

Note: If you call something like mon.getSize, the result will be equivalent to calling mon1.getSize, because mon2's results are not store and returned. Theoretically, you could do so, effectively doubling the number of results you get.

#3 Exerro

  • Members
  • 801 posts

Posted 15 August 2015 - 11:46 AM

The 3 lines:
	local result = {v( ... )} --#this'll call mon1's function, and store any values returned
	mon2[ k ]( ... ) --#this just calls mon2's function
	return unpack( result ) --#this returns whatever mon1's function would've returned.

can be simplified to this, assuming the order in which the functions are called doesn't matter:
	mon2[ k ]( ... ) --#this just calls mon2's function
	return v( ... ) --#this returns whatever mon1's function would've returned.

Also, you may want to consider changing 'monitor_touch' events on either monitor to 'mouse_click' events so you can interact with the monitor. Not sure if this is what you want though.

Edited by awsumben13, 15 August 2015 - 11:46 AM.


#4 em_niss

  • New Members
  • 2 posts

Posted 18 August 2015 - 06:26 PM

Thanks for the replies! I'll try this as soon as I can!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users