Running one program simultainiously on two...
em_niss 15 Aug 2015
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.
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.
KingofGamesYami 15 Aug 2015
Well, you can do what you want, but it's rather hackish and usually has some problems.
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.
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.
Exerro 15 Aug 2015
The 3 lines:
can be simplified to this, assuming the order in which the functions are called doesn't matter:
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.
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.