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

printer script

Started by kintick, 02 November 2012 - 10:31 PM
kintick #1
Posted 02 November 2012 - 11:31 PM
I've been writing a script to run printers.

Currently you need to put the lines within the program, but i will update this later so that you can enter them at run-time.

Remember, there is a maximum of 6 pages that can be printed at once.


Changelog:
  • V1.1:
    • you can set the number of the page that printing can start on
      • print <side> <pagetostarton> <title>
  • V1.1 Bugs:
    • Sometimes, certain pages may be duplicated, this may happen when you print from numbers higher than 1
      • e.g: 7,8,9,10,11,12
      • Confirmed at 7 &amp; 12
  • V1.0:
    • Initial Release
      • Ability to print as many pages as wanted, however has a max of 6


File: print



function printUsage()
	print( "Usage: print <side> <pagetostart> <title>" )
	return
end

local tArgs = { ... }
if #tArgs < 3 then
	printUsage()
	return
end

local pages = { {"Title: Page 1","Line1","Line2","Line3","Line4","Line5"},
                {"Title: Page 2","Line1","Line2","Line3","Line4","Line5"},
                {"Title: Page 3","Line1","Line2","Line3","Line4","Line5"},
                {"Title: Page 4","Line1","Line2","Line3","Line4","Line5"},
                {"Title: Page 5","Line1","Line2","Line3","Line4","Line5"},
                {"Title: Page 6","Line1","Line2","Line3","Line4","Line5"},
                {"Title: Page 7","Line1","Line2","Line3","Line4","Line5"},
                {"Title: Page 8","Line1","Line2","Line3","Line4","Line5"},
                {"Title: Page 9","Line1","Line2","Line3","Line4","Line5"},
                {"Title: Page 10","Line1","Line2","Line3","Line4","Line5"},
                {"Title: Page 11","Line1","Line2","Line3","Line4","Line5"},
                {"Title: Page 12","Line1","Line2","Line3","Line4","Line5"},
                {"Title: Page 13","Line1","Line2","Line3","Line4","Line5"},
                {"Title: Page 14","Line1","Line2","Line3","Line4","Line5"}};

local sSide = tArgs[1]
if peripheral.getType( sSide ) ~= "printer" then
	print( "No printer on "..sSide.." side" )
	return
end

local printer = peripheral.wrap( sSide )

title = ""
yCord = 0
for i=3, table.getn(tArgs) do
	title = title ..tArgs[i] .." "
end

for i = tArgs[2], table.getn(pages) do
	if printer.getInkLevel() < 1 then
		print( "Please Refil Ink!" )
	end

	if printer.getPaperLevel() < 1 then
		print( "Please Refil Paper!" )
	end

	if printer.getPaperLevel() > 0 then
		if printer.getInkLevel() > 0 then
			if printer.newPage() then
				printer.setPageTitle( title )
				for n = 0, table.getn(pages[i]) do
					printer.setCursorPos( 1, yCord )
					printer.write( pages[i][n] )
					yCord = yCord + 1
				end
				printer.endPage()
				yCord = 0
			end
		end
	end
end

kazagistar #2
Posted 04 November 2012 - 07:40 AM
I dont understand what the point of this program is. Could you explain it a bit better?
kintick #3
Posted 05 November 2012 - 09:53 PM
I dont understand what the point of this program is. Could you explain it a bit better?

It just makes printing a bit easier. It's far from finished though.
nutcase84 #4
Posted 04 March 2013 - 01:26 PM
Nice work!