Jump to content




Disable new line?


  • You cannot reply to this topic
3 replies to this topic

#1 RoD

  • Members
  • 313 posts

Posted 13 April 2014 - 10: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.

#2 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 13 April 2014 - 10: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 by Bomb Bloke, 13 April 2014 - 10:21 PM.


#3 MKlegoman357

  • Members
  • 1,170 posts
  • LocationKaunas, Lithuania

Posted 14 April 2014 - 08: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


#4 RoD

  • Members
  • 313 posts

Posted 14 April 2014 - 11:31 AM

View PostMKlegoman357, on 14 April 2014 - 08:34 AM, said:

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 :)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users