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

Question about advanced monitors

Started by BrolofTheViking, 12 December 2012 - 01:15 PM
BrolofTheViking #1
Posted 12 December 2012 - 02:15 PM
I've started using advanced monitors for the first time, in order to make a graphical interface for my next massive project I'm not likely to ever finish.
I encountered an error while trying to display colors on a monitor
My code is this, which works perfectly fine, for writing the colors on the computer screen.

m = peripheral.wrap("left")
for x=1,5,2 do
  for y = 1,5,2 do
	paintutils.drawPixel(x,y,colors.orange)
	paintutils.drawPixel(x+1,y,colors.green)
  end
end
However, if I attempt to instead draw on the monitor to the left, using the wrapped value, and change the code as such to

m = peripheral.wrap("left")
for x=1,5,2 do
  for y = 1,5,2 do
	m.paintutils.drawPixel(x,y,colors.orange)
	m.paintutils.drawPixel(x+1,y,colors.green)
  end
end
I encounter the error "attempt to index ? (a nil value)"
so clearly this is not the method I should use to draw on the monitors, but I can't figure out what is.

Further information: Using a simple shell.run is impractical, as I have this computer controlling multiple monitors using the peripheral cables addon, and if I were to use shell.run I would have to split up the information this computer receives to multiple other computers, which would involve editing my existing programs, which I don't want to do because I'm stubborn and obstinate, and there should be a way to do what I'm trying to do.</rant>
Lyqyd #2
Posted 12 December 2012 - 02:18 PM
When wrapping the peripheral, you're simply creating a table of the methods it exposes. It does not re-expose the paintutils API, which is why you would be receiving that error. Instead of that, try using term.redirect(m) before the loops and term.restore() afterward. This sets the target output for all term functions to the specified table, then restores it back to the previous output target afterwards.
BrolofTheViking #3
Posted 12 December 2012 - 02:35 PM
When wrapping the peripheral, you're simply creating a table of the methods it exposes. It does not re-expose the paintutils API, which is why you would be receiving that error. Instead of that, try using term.redirect(m) before the loops and term.restore() afterward. This sets the target output for all term functions to the specified table, then restores it back to the previous output target afterwards.
Awesome, thanks.