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

Help with a CC code.

Started by soulrunner, 13 April 2014 - 02:22 PM
soulrunner #1
Posted 13 April 2014 - 04:22 PM
hello. can anyone help me with my CC program? pastebin.com/B0rTwu1x Error: startup:2: attempt to indez ? (a nill value).
Thank you in advanced.
Lignum #2
Posted 13 April 2014 - 06:03 PM
The error you're getting looks like it's from line 3, because line 2 is just fine. Was that a typo?


m.paintutils.drawImage(Lo ,1 ,1)

Here's the problem. Sadly, you can't use paintutils on anything other than term (correct me if I'm wrong). So you're going to have to write your own drawImage function. The simplest way to do this is to copy the function from paintutils and modify it to suit your needs.

So replace that line with:


for y=1,#Lo do
local tLine = Lo[y]
for x=1,#tLine do
  if tLine[x] > 0 then
   term.setBackgroundColor( tLine[x] )
   term.setCursorPos( x + xPos - 1, y + yPos - 1 )
   term.write(" ")
  end
end
MKlegoman357 #3
Posted 13 April 2014 - 06:23 PM
The error you're getting looks like it's from line 3, because line 2 is just fine. Was that a typo?


m.paintutils.drawImage(Lo ,1 ,1)

Here's the problem. Sadly, you can't use paintutils on anything other than term (correct me if I'm wrong). So you're going to have to write your own drawImage function. The simplest way to do this is to copy the function from paintutils and modify it to suit your needs.

So replace that line with:


for y=1,#Lo do
local tLine = Lo[y]
for x=1,#tLine do
  if tLine[x] > 0 then
   term.setBackgroundColor( tLine[x] )
   term.setCursorPos( x + xPos - 1, y + yPos - 1 )
   term.write(" ")
  end
end

Not quite right (also, that code would error). when you wrap a peripheral using peripheral.wrap you get a table with all functions that particular peripheral has. paintutils is not a part of a monitor. It is actually written in plain CC Lua. Here is a list of available functions for a monitor.

To get paintutils to work with monitors the easiest way would be to use term.redirect. It redirects the terminal so all calls in term table would result in calls to wrapped monitor table.
Edited on 13 April 2014 - 04:26 PM