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

draw an image on a monitor

Started by tuffy45, 23 September 2014 - 06:08 PM
tuffy45 #1
Posted 23 September 2014 - 08:08 PM
Hello, today a want to display a paint image but I can not do.

my image is called "punk".

my code:

m = peripheral.wrap("right")
image = paintutils.loadImage("punk")
m.paintutils.drawImage(image,1,1)

my error:

test:3: attempt to index ? (a nil value)

please help me :(/>

Excuse my english, i'm french.
Engineer #2
Posted 23 September 2014 - 10:28 PM
the monitor (the variable 'm') only has draw functions, like the Term API. You will need to use term.redirect and term.restore as follows:

local m = peripheral.wrap("right")
term.redirect(m)
-- Now all term calls will go to the monitor instead
local image = paintutils.loadImage("punk")
paintutils.loadImage(image, 1, 1)
term.restore()
-- Now the term.* calls will draw on the terminal again
Lyqyd #3
Posted 23 September 2014 - 11:24 PM
You'll need to use term.redirect twice, actually. Term.restore only exists on pre-1.64 versions.

You can also gain compatibility with both ways of doing it by using this for term.redirect:


local _old = term.redirect(m)

And this for term.restore:


if _old then
  term.redirect(_old)
else
  term.restore()
end
KingofGamesYami #4
Posted 23 September 2014 - 11:30 PM
Engineer is correct, however in CC 1.6+ term.restore() is no longer available and term.redirect() works differently:

local m = peripheral.wrap("right")
local oldterm = term.redirect(m)
-- Now all term calls will go to the monitor instead
local image = paintutils.loadImage("punk")
paintutils.loadImage(image, 1, 1)
term.redirect( oldterm )
-- Now the term.* calls will draw on the terminal again