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

Printer prints everything on 1 line

Started by android4682, 22 April 2014 - 05:40 PM
android4682 #1
Posted 22 April 2014 - 07:40 PM
For some reason my printer prints a whole story with multiple lines on 1 line instead of multiple.

Printing Script:

function printing(PTitle)
printer.newPage()
printer.setPageTitle(PTitle)
printer.write(printcontent)
printer.endPage()
print("Printing Done!")
sleep(3)
end

This is where printcontent comes from:

local scoutFileFull = fs.open("classes/scoutFull", "r")
if scoutFileFull then
printcontent = scoutFileFull.readAll()
scoutFileFull.close()
end

I can't find the problem so I hope someone here does.

I attached a screenshot of the Printed Page how it is now :/

I had a rough day so I'm not as accurate as normal.
That should explain why I'm making mistakes in my code.
Edited on 22 April 2014 - 05:51 PM
Lyqyd #2
Posted 22 April 2014 - 08:01 PM
This is the same issue you'd have trying to use the term.write or monitor.write functions to write out text with line breaks. The raw device.write functions will write out exactly what you tell them to. They don't care about special characters (line breaks), they'll just write a "?" character instead. With a printer, you will need to manually control the printing process, moving the print cursor and writing the text out a line at a time.
android4682 #3
Posted 22 April 2014 - 08:10 PM
This is the same issue you'd have trying to use the term.write or monitor.write functions to write out text with line breaks. The raw device.write functions will write out exactly what you tell them to. They don't care about special characters (line breaks), they'll just write a "?" character instead. With a printer, you will need to manually control the printing process, moving the print cursor and writing the text out a line at a time.

Ok… That sounds like a pain in the ass. But alright.

Is there any way to do make this an automatic process? Because I got 38 lines of text. :P/>
Edited on 22 April 2014 - 06:16 PM
Lyqyd #4
Posted 22 April 2014 - 09:38 PM
You could look at the implementation of write() in the bios.lua and adapt it for use with printers, or use a printing program someone else has written.
electrodude512 #5
Posted 22 April 2014 - 09:43 PM
Wait, so I can term.wrap(printer)? Never realized that, although it's obvious that term.wrap will take any table with the right methods. Cool!
Lyqyd #6
Posted 22 April 2014 - 10:18 PM
No, you can't term.redirect to a printer (there is no term.wrap). That's why I suggested adapting the bios.lua write() function to use turtles.
LDShadowLord #7
Posted 22 April 2014 - 10:52 PM
/shamelessplug This should help with your printer problem (It should work, though is not guaranteed to as I no longer support this API.) http://pastebin.com/zUKuFHPz
android4682 #8
Posted 23 April 2014 - 08:36 AM
I tried to look into the bios but that was too complicated for me. I didn't know what I need to do to fix it.
I also tried that plugin but that still prints everything on 1 line :/

Is there no other way to fix this?
CometWolf #9
Posted 23 April 2014 - 10:46 AM
Use something like string.gmatch or string.find and string.sub. Index each line of the string into a table and then iterate through the table while printing each line.
Bomb Bloke #10
Posted 23 April 2014 - 11:03 AM
That stirs a memory - this might be useful.
android4682 #11
Posted 23 April 2014 - 12:00 PM
I made a sort of fix:


CCP1Limit = 0
CCP1 = 0
local fileP1 = fs.open("classes/scoutP1", "r")
local contentP1 = {}
repeat
contentP1[CCP1] = fileP1.readLine()
CCP1 = CCP1+1
contentP1[CCP1] = "\n"
CCP1 = CCP1+1
until fileP1.readLine() == nil
CCP1Limit = CCP1
fileP1.close()
CCP1 = 0
repeat
print(contentP1[CCP1])
CCP1 = CCP1+1
until CCP1 == CCP1Limit
print("")
print("Printing to screen done!")

This is working great for me. The next thing is testing this on my printer…


Never Mind this.
Edited on 23 April 2014 - 10:07 AM