2 posts
Posted 15 August 2015 - 01: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 on 14 August 2015 - 11:49 PM
3057 posts
Location
United States of America
Posted 15 August 2015 - 03: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.
797 posts
Posted 15 August 2015 - 12:46 PM
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 on 15 August 2015 - 10:46 AM
2 posts
Posted 18 August 2015 - 07:26 PM
Thanks for the replies! I'll try this as soon as I can!