3 posts
Posted 15 May 2014 - 04:36 PM
Hello! I am a Computercraft noob who knows little more than what Internet tutorials have taught me.
I need some help with my program:
print("What is the pictures name?")
x = read()
print("What directory is the picture stored in?")
y = read()
paintutil = peripheral.wrap("monitor_0")
paintutil.loadImage(x,y)
The program is meant to allow my friends who don't know any computercraft at all to load their pictures on to the monitor in the network.
I have two advanced computers and one advanced monitor connected via wired modems and network cables
When I run it I get: loadpicture:6: attempt to call nill
I think I can understand why this isn't working: The paintutils.loadImage() function expects a string, not a variable,
but how would I get it to work?
Thanks,
Cuboidium
350 posts
Posted 15 May 2014 - 05:49 PM
change paintutil to paintutilsplus: you need to do like this:
print("What directory is the picture stored in?")--removed the obsolete "name" propmt.
y = read()
mon= peripheral.wrap("left")
image = paintutils.loadImage(y, 1,1)
paintutils.drawImage( image )
I am not sure about running it on a monitor but there's alaways google. http://www.computercraft.info/forums2/index.php?/topic/5641-146-additional-paintutils/
Edited on 15 May 2014 - 03:53 PM
1114 posts
Location
UK
Posted 15 May 2014 - 05:52 PM
These tutorials must be terrible :P/>
Basically, what this means is that paintutil.loadImage does not exist. Also, you don't need two arguments for loading an image.
Code like this should work:
local monitor = peripheral.wrap("monitor_0")
print("What is the picture's name?")
local pictureName = read()
print("What directory is the picture stored in?")
local pictureDir = read()
local picturePath = fs.combine(pictureDir, pictureName) -- Getting the full path to the image
local myImage = paintutils.loadImage(picturePath) -- Creating an image object
term.redirect(monitor) -- This redirects all output to the monitor
paintutils.drawImage(myImage, 0, 0) -- The 0s represent the coordinates of where to draw the image.
term.redirect(term.native()) -- Change back to the computer screen.
Also, remember to put
local before defining a variable, it is good practice.
change paintutil to paintutils
That would *not* help.
Edited on 17 May 2014 - 04:29 PM
8543 posts
Posted 15 May 2014 - 05:53 PM
That won't even help, since he's trying to replace the API with a wrapped monitor.
OP, you should wrap the monitor into a different variable, like `mon`, then redirect the terminal to mon and draw your image using the paintutils API.
Got ninja'd, so edit to add that the code above should work in the 1.5 builds of ComputerCraft, but will not work in 1.6 and later.
350 posts
Posted 15 May 2014 - 05:56 PM
Now i know, but i didnt know how to do that on the monitor. But while searching i fount that:
-- Immediately invoke a method without wrapping
peripheral.call("top", "write", "Hello World!")
Can run paintutils.drawImage instead of write, or not?
1610 posts
Posted 15 May 2014 - 06:47 PM
These tutorials must be terrible :P/>/>
Basically, what this means is that paintutil.loadImage does not exist. Also, you don't need two arguments for loading an image.
Code like this should work:
local monitor = peripheral.wrap("monitor_0")
print("What is the picture's name?")
local pictureName = read()
print("What directory is the picture stored in?")
local pictureDir = read()
local picturePath = fs.combine(pictureDir, pictureName) -- Getting the full path to the image
local myImage = paintutils.loadImage(picturePath) -- Creating an image object
term.redirect(monitor) -- This redirects all output to the monitor
paintutils.drawImage(myImage, 0, 0) -- The 0s represent the coordinates of where to draw the image.
term.restore() -- Change back to the computer screen.
Also, remember to put
local before defining a variable, it is good practice.
change paintutil to paintutils
That would *not* help.
term.restore has been phased out in 1.6. Use term.redirect(term.native()) or save the value of term.current() in a variable before redirecting and then redirect back after.
8543 posts
Posted 15 May 2014 - 07:52 PM
Now i know, but i didnt know how to do that on the monitor. But while searching i fount that:
-- Immediately invoke a method without wrapping
peripheral.call("top", "write", "Hello World!")
Can run paintutils.drawImage instead of write, or not?
Of course not. The monitor exposes the methods of a term object as well as setTextScale. There's no term.paintutils.drawImage, so why would there be such methods on the monitor? However, the paintutils functions call the term functions, so redirecting the terminal to a wrapped monitor will make the paintutils methods draw onto the monitor.
3 posts
Posted 15 May 2014 - 08:09 PM
I am using computercraft version 1.58 if that helps
3 posts
Posted 17 May 2014 - 01:06 PM
When I try RoDs program I get paintutils:92: attempt to get length of nill
1114 posts
Location
UK
Posted 17 May 2014 - 06:29 PM
-snip-
I haven't been using CC for a while, thanks for the advice :P/>