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

\n Doesn't Work In Term.write

Started by civilwargeeky, 14 October 2013 - 10:13 PM
civilwargeeky #1
Posted 15 October 2013 - 12:13 AM
Is this intended or am I missing something?
Using Minecraft 1.5.2 with corresponding CC version on FTB Unleashed Pack
I had the same results using CC Desk (stable version)

term.write("\n")
makes "?"

print("\n")
makes "

" as expected.
So is this a bug, or something intended, or am I not doing something right?

Also carriage returns (\r) do not work either
LBPHacker #2
Posted 15 October 2013 - 12:27 AM
Of course they don't work with term.write. \n is handled by write, and that's why print is capable of handling it as well (print calls write).
Lyqyd #3
Posted 15 October 2013 - 12:32 AM
To restate, print() calls write(), which handles line breaks and word wrapping, which then calls term.write(). \n isn't handled by term.write() just like it isn't handled by monitor.write(). That's why we have the write() and print() functions!
Anavrins #4
Posted 15 October 2013 - 12:59 AM
To restate, print() calls write(), which handles line breaks and word wrapping, which then calls term.write(). \n isn't handled by term.write() just like it isn't handled by monitor.write(). That's why we have the write() and print() functions!
Of course, but write() and print() doesn't work on monitors!
Unless you use term.redirect/restore, but this has the disadvantage of not being able to use both the computer terminal and a monitor at the same time…
Why is \n not handled by term/monitor.write() in the first place anyway?
theoriginalbit #5
Posted 15 October 2013 - 01:50 AM
Of course, but write() and print() doesn't work on monitors!
Unless you use term.redirect/restore, but this has the disadvantage of not being able to use both the computer terminal and a monitor at the same time…
There is no disadvantage there, redirect to the monitor and print to it, then restore to the terminal and print to it, then yield. It will appear as though you're writing to both at the same time

Why is \n not handled by term/monitor.write() in the first place anyway?
For the same reason your GPU doesn't handle them. Its the "hardware interface", hardware interfaces are not designed to handle input, they're designed to get valid input.
immibis #6
Posted 16 October 2013 - 01:53 AM
Why is \n not handled by term/monitor.write() in the first place anyway?
Imagine the term API had only term.setChar(x, y, char) which sets a single character at a certain location.
You would not expect term.setChar(x, y, "\n") to start a new line, you'd expect it to print \n on the screen - except \n can't actually be displayed so instead it displays a ?.
term.setCursorPos and term.write are like this hypothetical term.setChar, but writing multiple characters at once (possibly for efficiency).