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

How to display an image onto the monitor using paintutils

Started by SooBahkCode, 13 August 2014 - 01:41 AM
SooBahkCode #1
Posted 13 August 2014 - 03:41 AM
I am making a game and I am using this bit of code to display an image called MainMenu. Whenever I try testing this function, it responds with: attempt to index ? (a nil value)
How do I fix it?

function mainMenu()
term.clear()
term.getSize()
paintutils.loadImage(paint.MainMenu)
paintutils.drawImage(MainMenu, 1, 1)
end
theoriginalbit #2
Posted 13 August 2014 - 03:55 AM
Take a look at paintutils.loadImage and paintutils.drawImage on the wiki to see the usage of each function.
SooBahkCode #3
Posted 13 August 2014 - 04:05 AM
I did but it dosent make any sense to me
plz help
flaghacker #4
Posted 13 August 2014 - 06:54 AM
paintutils.loadimage returns a table with the image data, paintutils.drawImage prints it to the screen. So…

paintutils.drawImage(paintutils.loadImage(path), xPos, yPos)
Try harder to understand the wiki, this could all be found there.
Edited by
Bomb Bloke #5
Posted 13 August 2014 - 07:06 AM
Psst - you missed a spot! ;)/>

SooBahkCode, if you're still having trouble, maybe elaborate on where you're defining "paint.MainMenu".
SooBahkCode #6
Posted 13 August 2014 - 03:33 PM
Thnkz for the help. (By the way, im new at coding and couldnt understand the wiki and it didnt say to put paintutils.loadImage() inside of paintutils.drawImage ()!)
theoriginalbit #7
Posted 13 August 2014 - 04:31 PM
well no, you don't have to do that. if you take a look at the example code from the wiki


local image = paintutils.loadImage("bar")
paintutils.drawImage(image, 3, 5)

this will load the image file 'bar' into a variable called image. you may then notice that image is used as the first value for drawImage, this gives it the image that was loaded from the file so that it can be drawn.
SooBahkCode #8
Posted 13 August 2014 - 04:45 PM
Is this what you want me to do?

function mainMenu()
term.clear()
term.getSize()
local image = paintutils.loadImage(paint.MainMenu)
paintutils.drawImage(image, 1, 1)
end


If so, its giving me the same error.
SooBahkCode #9
Posted 13 August 2014 - 04:51 PM
Nevermind! I finally got it working. Thanks for helping! It means a lot. Your advice really helped.