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

Printer Help

Started by ClassicRockFan, 07 March 2014 - 09:13 PM
ClassicRockFan #1
Posted 07 March 2014 - 10:13 PM
Hey Guys, I am having an issue with this program I am writing. Basically, it's a printer program and it asks you a serious of questions. But, I'm having an issue with it setting the page title when its not supposed to. Here is the code…

p = peripheral.wrap("printer_1")
function startprint()
  term.clear()
  term.setCursorPos(1,1)
  p.newPage()
  local ink = p.getInkLevel()
  local paper = p.getPaperLevel()
  print(" You have "..ink.." ink and "..paper.." pieces of paper.")
  print("Enter your desired message: ")
  term.write(" ")
  printin = read()
  term.write("Enter Paper Title(Enter none if not desired): ")
  title = read()
  --Here is where the error would occur																																												     if title ~= none or None then
   p.setPageTitle(title)
  end
  p.write(printin)
  p.endPage()
  print("Print Job Successful")
end
function wait()
term.clear()
term.setCursorPos(1,1)
term.write("What Would you like to do? ")
input = read()
if input == "print" then
startprint()
end
end
wait()
Thanks in advance for all of the help! - CRF
Edited on 07 March 2014 - 09:15 PM
CometWolf #2
Posted 07 March 2014 - 11:48 PM
I've never used a printer before, but what does it set the title to? You're passing it a blank string (""), but i dunno how that affects the printer to be honest.
ClassicRockFan #3
Posted 08 March 2014 - 12:25 AM
I've never used a printer before, but what does it set the title to? You're passing it a blank string (""), but i dunno how that affects the printer to be honest.
All that te extra term.write(" ") is doing is waiting for input on the next line rather than on the one that says why you are entering. But I'm having an issue with it devoting the value of title not be non or None. Rather than checking if it's not, it appears to be checking like an == rather than a ~=.

That is the only part that doesn't work by the way.
Edited on 07 March 2014 - 11:26 PM
CometWolf #4
Posted 08 March 2014 - 01:12 AM
I was talking about this part, read() will return an empty string if you don't input anything. This empty string is then stored in title and passed to the printer

  title = read()
  --Here is where the error would occur																																																																																							  if title ~= none or None then
   p.setPageTitle(title)

Oh wow, i just realized you put "if title ~= none or None then" WAAAAAAY to the right of your comment…
title will always be unequal to none or None, since those are not keywords, just undefined variables, and title is an empty string. The keyword you want is nil, but anyways, what you gotta change it to is

if #title > 0 then
And take it off the comment line obviously
ClassicRockFan #5
Posted 08 March 2014 - 01:50 AM
I didn't realize that none was a syntax. Oh well. And the code doesn't appear on the same line on my screen. Oh well. I'll try tht out tomorrow. Thanks for your help.

BTW, I will be adapting this to sort if act like a cash register where it will display a price on a monitor, and print out two copies of a receipt and allow a clerk to retrieve the purchased items
Edited on 08 March 2014 - 12:52 AM
CometWolf #6
Posted 08 March 2014 - 02:04 AM
I didn't realize that none was a syntax.
Im saying it's not.
ClassicRockFan #7
Posted 08 March 2014 - 12:06 PM
I misunderstood what you were saying. If I wanted to use none, then it would have to be "none". But I will be using your thing instead. Thanks for the help. I'll let you know how the final code turns out
Edited on 08 March 2014 - 04:18 PM