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

Multiple Monitors

Started by Lux, 19 August 2013 - 01:55 AM
Lux #1
Posted 19 August 2013 - 03:55 AM
Hi! I wrote a program for control an elevator with monitors but I need put the buttons for UP and DOWN in all monitors (4 monitors). I'm using CCable for connect the monitors (I have the MInecraft 1.4.7 and ComputerCraft 1.5). I tried to use:

monitor = peripheral.wrap("back:red")
monitor = peripheral.wrap("back:green")
monitor = peripheral.wrap("back:blue")
monitor = peripheral.wrap("back:cyan")
but doesn't work. I tried to use:

monitor = peripheral.wrap("back:red"),peripheral.wrap("back:green"),peripheral.wrap("back:blue"),peripheral.wrap("back:cyan")
And doesn't work either.
How can I do this? Sorry if my english is bad, I speak spanish. Thanks for read!
Lyqyd #2
Posted 19 August 2013 - 07:54 PM
Split into new topic.

You'll need to use each monitor individually. You can't just throw them all into a single variable, you'll only end up with one of them.
Lux #3
Posted 19 August 2013 - 08:06 PM
So, how can I do this?
Kingdaro #4
Posted 19 August 2013 - 08:10 PM
Either separate variables:

monitorRed = peripheral.wrap("back:red")
monitorGreen = peripheral.wrap("back:green")
monitorBlue = peripheral.wrap("back:blue")
monitorCyan = peripheral.wrap("back:cyan")

Or a table:

monitors = {
  peripheral.wrap("back:red");
  peripheral.wrap("back:green");
  peripheral.wrap("back:blue");
  peripheral.wrap("back:cyan");
}

--# where monitors[1] is the red monitor, monitors[2] is the green one, and so on.

This also works:

monitors = {
  red = peripheral.wrap("back:red");
  green = peripheral.wrap("back:green");
  blue = peripheral.wrap("back:blue");
  cyan = peripheral.wrap("back:cyan");
}

--# where monitors.red is the red monitor, monitors.green is the green one, and so on.
Lux #5
Posted 21 August 2013 - 12:09 AM
But I need run the same program in all monitors which the program has a clic event. So I need one variable for all monitors.

The code is:

mouseWidth = 0
mouseHeight = 0
-- I need a variable for here
monitor = peripheral.wrap("back:red")
-- And blue, green, cyan.
monitor.clear()
monitor.setCursorPos(1,1)
w,h=monitor.getSize()
print(w)
print(h)
monitor.setBackgroundColour((colours.blue))
monitor.setCursorPos(1,2)
monitor.write(" Subir ") -- "Up" in spanish
monitor.setCursorPos(1,4)
monitor.write(" Bajar ") -- "Down" in spanish
monitor.setBackgroundColour((colours.black))
function checkClickPosition()
  if mouseWidth > 0 and mouseWidth < 8 and mouseHeight == 2 then
	shell.run("arribabund") -- The program which push UP the elevator
  elseif mouseWidth > 0 and mouseWidth < 8 and mouseHeight == 4 then
	shell.run("abajobund") -- The progam which pull DOWN the elevator
	end
end
  
repeat
   event,p1,p2,p3 = os.pullEvent()
   if event=="monitor_touch" then
	 mouseWidth = p2
	 mouseHeight = p3
	 checkClickPosition()
	
   end
until event=="char" and p1==("x") -- For a easy exit in the test

Thanks!
Last1Here #6
Posted 21 August 2013 - 05:11 AM
Look at using a for loop and use the tables like kindaro. Wiki loops

Also you missed a ")" in the repeat loop when calling checkClickPosition()
Lux #7
Posted 21 August 2013 - 10:48 PM
Look at using a for loop and use the tables like kindaro. Wiki loops

Also you missed a ")" in the repeat loop when calling checkClickPosition()
Thanks for the reply but I don't know how to make this. :(/> Can you tell me?
And sorry for the ")", I forgot copy it.
Coderforlife #8
Posted 30 December 2013 - 05:14 PM
Hi! I wrote a program for control an elevator with monitors but I need put the buttons for UP and DOWN in all monitors (4 monitors). I'm using CCable for connect the monitors (I have the MInecraft 1.4.7 and ComputerCraft 1.5). I tried to use:

monitor = peripheral.wrap("back:red")
monitor = peripheral.wrap("back:green")
monitor = peripheral.wrap("back:blue")
monitor = peripheral.wrap("back:cyan")
but doesn't work. I tried to use:

monitor = peripheral.wrap("back:red"),peripheral.wrap("back:green"),peripheral.wrap("back:blue"),peripheral.wrap("back:cyan")
And doesn't work either.
How can I do this? Sorry if my english is bad, I speak spanish. Thanks for read!


monitors = {
peripheral.wrap("back");
peripheral.wrap("top");
peripheral.wrap("front");
--You could add tons of monitors here because the allMonitors function will write on every monitor!
}
function allMonitors()
  for i=1,#monitors do
    monitors[i].write("Hey there!")
    monitors[i].setCursorPos(1,1)
end
end
allMonitors()

I used this on my NoteWall program (http://pastebin.com/YhhQ8Zu3) today ;)/>
And I coded it in a way that you only need to add the monitors in the "monitors" table and you can do a for loop like I showed above to write the same thing on EVERY monitor!

I only registered to share this with you :D/>

Have fun ;)/>