2 posts
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.
1522 posts
Location
The Netherlands
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
8543 posts
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
3057 posts
Location
United States of America
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