Im trying to make a simple program for my server, for admin applications, but when someone types something too long, it goes off the page. Any fix?
0
2 replies to this topic
#1
Posted 08 May 2014 - 11:17 PM
#2
Posted 08 May 2014 - 11:47 PM
Since all the characters are the same length with the font CC uses (I believe), you can compare the amount of characters and divide that by the maximum that can fit per line. And you will get how many lines you will need (math.ceil it).
So something like:
Also, you can implement something fairly easy (when lines > paper size Y) to check if it reached the end of the page, then start a new page.
So something like:
local text = "blah"; local sX, sY = printer.getPageSize(); local lines = math.ceil(#text / sX) for y = 1, lines do local start = ((y - 1) * sX) + 1; local finish = y * sX; printer.setCursorPos(1, y) printer.write(text:sub(start, finish)); endThe math seemed to have worked out in my head, though I'm not sure it's entirely correct.
Also, you can implement something fairly easy (when lines > paper size Y) to check if it reached the end of the page, then start a new page.
Edited by HometownPotato, 08 May 2014 - 11:53 PM.
#3
Posted 09 May 2014 - 12:28 AM
you could just put:
printer = peripheral.wrap( "side" ) local px , py = printer.getPageSize() if px > "however long a page is" then -- cancel the input by using something.but HometownPotato has a better code with that part. (IF it does work)
Edited by cptdeath58, 09 May 2014 - 12:28 AM.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users