0

I'm trying to make a custom printing program for ComputerCraft, that can make more copies by one command and I have a problem. Every time a put a file into it, it doesn't break lines and puts ? where the line break is (\n). How do I do it correctly?

Problem should be somewhere here:

for i=1,copyNumber do
    printer.newPage();
    printer.setPageTitle(pageLabel);
    local h = fs.open(filePath, "r");
    local text = h.readAll();
    print("Tisknu:");
    write(text.."\n");
    printer.write(text);
    h.close();
    printer.endPage();
end
Sumurai8
  • 20,333
  • 11
  • 66
  • 100
Jake S.
  • 568
  • 6
  • 25
  • Probably, you should set new cursor position using `printer.setCursorPos(1,line_no)` before writing text into new line. – Egor Skriptunoff Apr 28 '13 at 09:25
  • You are opening the file in text mode, then reading it into a buffer in one operation. That produces a buffer with lines separated by `\n` characters. If your printer needs CRLF sequences as line endings, then you should prefer to read the file a line at a time and inserting the correct line endings as required, or manipulate a printer cursor as mentioned by Egor. I don't do Minecraft and can only speak to the Lua edge of things otherwise. – RBerteig Apr 29 '13 at 22:46

1 Answers1

0

Try this:

for i=1,copyNumber do
    printer.newPage();
    printer.setPageTitle(pageLabel);
    local h = fs.open(filePath, "r");
    local text = h.readLine(); --Read one line
    while(text != nil) --If line isn't nill
        printer.write(text); --Write the line
        _,y = printer.getCursorPos() --Get the current cursor pos.
        printer.setCursorPos(1,y+1); --Move one line down
        text = h.readLine(); --Read the next line
    end
    h.close(); --Close the file
    printer.endPage(); --End the page
end
Meoiswa
  • 666
  • 4
  • 12