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

Disable new line?

Started by RoD, 13 April 2014 - 09:19 PM
RoD #1
Posted 13 April 2014 - 11:19 PM
Hey everyone, i am making a program and i added some theme support and i want to print a big space (not all) of the screen. I tried to use paintutils to draw an image, but it would print only the color that i choose in paint. I am trying to print line by line and it worked until the last line, where it changed to a new line. So i cant print the last line becasue the computercraft will always change to a new line. Any sugestions or anyone knows how to disable the new line thing? Thanks in advance.
Bomb Bloke #2
Posted 13 April 2014 - 11:21 PM
I'm not entirely sure I understand what you're on about, but I can tell you that "print" will perform a linebreak at the end of whatever text you pass it, and "write" won't. "term.write" will avoid word-wrap, too.
Edited on 13 April 2014 - 09:21 PM
MKlegoman357 #3
Posted 14 April 2014 - 09:34 AM
When dealing with GUI I highly encourage people to use term.write. Why not print or write? print and write functions apply new lines and word wrapping which is totally unnecessary when it comes to drawing a GUI. I actually had a problem when I was making an OS: I couldn't write anything to the right side of the screen because of word wrapping print and write used.

Also, if you just want to draw some lines, boxes or pixels you can always use paintutils.drawLine and paintutils.drawPixel or write your own drawing algorithms. Here's a simple function which would draw a box:


local function drawBox (x, y, width, height, color)
  if color then
    term.setBackgroundColor(color)
  end

  for h = y, y + height - 1 do
    term.setCursorPos(x, h)
    term.write(string.rep(" ", width))
  end
end

Which you could use like this:


drawBox(3, 2, 10, 7, colors.green) -- Draws a 10 wide and 7 tall green box who's top-left corner is at X: 3 and Y: 2
RoD #4
Posted 14 April 2014 - 12:31 PM
When dealing with GUI I highly encourage people to use term.write. Why not print or write? print and write functions apply new lines and word wrapping which is totally unnecessary when it comes to drawing a GUI. I actually had a problem when I was making an OS: I couldn't write anything to the right side of the screen because of word wrapping print and write used.

Also, if you just want to draw some lines, boxes or pixels you can always use paintutils.drawLine and paintutils.drawPixel or write your own drawing algorithms. Here's a simple function which would draw a box:


local function drawBox (x, y, width, height, color)
  if color then
	term.setBackgroundColor(color)
  end

  for h = y, y + height - 1 do
	term.setCursorPos(x, h)
	term.write(string.rep(" ", width))
  end
end

Which you could use like this:


drawBox(3, 2, 10, 7, colors.green) -- Draws a 10 wide and 7 tall green box who's top-left corner is at X: 3 and Y: 2
So, explain one thing: Using write instead of print will disable the computer to change the line? Oh i get it now, because when print is used it prints whathever you want and automaticaly change the line. Thanks :)/>