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

"For" loop with an "and", and "paintutils" problem!

Started by Strite, 13 December 2013 - 10:23 PM
Strite #1
Posted 13 December 2013 - 11:23 PM
Heyo guys!
So, I was testing some stuff with "x" and "y" positions in a creative world, just to get more used to it. While I was testing, I tried to make something like a horizontal line, no real reason behind it, again, just testing, and for that I needed a "for" loop with a "and" condicional inside it, and I don't even know if that's possible. The big question is, is it? Here's the code.



for i = 1,51  and i2 = 1,19 do
term.setCursorPos(i,i2)
print (".")
end

And also, if you guys have any tips related to using positions in a monitor, or a computer, just tell me, I really need some of those!
See ya!

EDIT: And just so I don't need to create another topic right away, I might as well just use this one.
I'm having a problem with the drawLine command from the paintutils API.

The code: pastebin.com/rqCgGd3n

What I want to do is to draw a horizontal line, starting and x position 1, and y position 1 - So it draws the line right at the top of the screen. But, for some reason, it's filling the whole screen with the color I'm giving, in this case black! I changed the color of the background to white, so, the result should be the white background with a black line on top. But that isn't happening!
Any ideas why?
Edited on 13 December 2013 - 10:54 PM
distantcam #2
Posted 13 December 2013 - 11:46 PM
'and' is used as part of a conditional, but for loops don't need a conditional.

What you want is 2 for loops, one inside the other.

for i = 1, 51 do
  for i2 = 1, 19 do
    term.setCursorPos(i, i2)
    print(".")
  end
end
Strite #3
Posted 13 December 2013 - 11:56 PM
Oh, I see, thanks distantcam, it really helped!

And, by the way, I edited the main post, I'm getting another problem, could you help me with that one as well? Sorry for the newbie behavior.
Bomb Bloke #4
Posted 14 December 2013 - 01:03 AM
term.setBackgroundColor() doesn't work that way - it only applies to the background of text written to the screen after calling it. Fortunately, term.clear() appears to function by writing a whole lot of spaces, in that it'll change the entire screen to whatever the background colour is currently set to.
Ajt86 #5
Posted 14 December 2013 - 01:44 AM
Instead of using term.clear() after setting the background color, change the cursor position to where you want to draw a coloured line and use term.clearLine()
TheOddByte #6
Posted 14 December 2013 - 07:45 PM
When you have set the background color to for example black and then use term.clear() it will fill the screen with black, So you have to first set the background color to white and then use term.clear(), Then you can set the background color to black and draw the line.