-- a function you cant access ;P local function round(num, idp) local mult = 10 ^ (idp or 0) return (math.floor(num * mult + 0.5) / mult) end function printLog(log, side, fromLn, toLn) if open == true then error("Log must be ended before printing") end if not fs.exists( "logs/"..log..".log") then error("Log does not exist") end h = fs.open("logs/"..log..".log", "r") page = {} while h.readLine() ~= nil do local ln = h.readLine() table.insert(page, ln) end p = peripheral.wrap(side) p.newPage() local paper = p.getPaperLevel() local ink = p.getInkLevel() local w, h = p.getPageSize() local doc = {} for i = fromLn, toLn do table.insert(doc, page[i]) end local length = 0 for i = 0, #doc do length = length + #doc[i] end local size = w*h local pages = round(length/size, 0) if pages > paper then error("not enough paper") end if pages > ink then error("not enough ink") end for i = 0, pages do p.newPage() p.setPageTitle(log.." page:"..i) for indx = 0, size do p.write(doc[indx]) end p.endPage() end end"log:91 attempt to get length of nil" it says, any suggestions?
2
Splitting a massive string to print with
Started by samdeman22, Mar 06 2013 09:59 AM
peripheral help
27 replies to this topic
#21
Posted 30 March 2013 - 08:21 AM
Aha, a new problem,
#22
Posted 30 March 2013 - 08:31 AM
You're starting the loop
if there isn't a value at doc[0], it can't get the length of it.
for i = 0, #doc do length = length + #doc[i] endat 0 instead of 1.
if there isn't a value at doc[0], it can't get the length of it.
#23
Posted 30 March 2013 - 11:43 AM
faubiguy, on 30 March 2013 - 08:31 AM, said:
You're starting the loop
if there isn't a value at doc[0], it can't get the length of it.
for i = 0, #doc do length = length + #doc[i] endat 0 instead of 1.
if there isn't a value at doc[0], it can't get the length of it.
#24
Posted 30 March 2013 - 12:55 PM
nope, this time it actually runs, but it just fills the tray with 5 blank pages :/ Can anyone suggest a better print function to what I have? I need to be able to print a file from a certain line to a certain line so basically (log, side, fromLn, toLn) where log is the file, side is the printer, and from/toLn are the from/to line.
#25
Posted 30 March 2013 - 12:57 PM
oh and you must use this at the beginning
open is defined in the rest of the API
if open == true then error("Log must be ended before printing") end if not fs.exists( "logs/"..log..".log") then error("Log does not exist") end h = fs.open("logs/"..log..".log", "r")ok
open is defined in the rest of the API
#26
Posted 31 March 2013 - 01:31 AM
could the reason it prints blank pages be:
for i = 0, pages do p.newPage() p.setPageTitle(log.." page:"..i) for indx = 0, size do p.write(doc[indx]) end p.endPage() endshould this be for i = 1, pages and indx = 1, size rather than 0, pages and 0, size?
#27
Posted 31 March 2013 - 10:13 AM
Yes.. doc table doesn't have a 0 index
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users