Jump to content




Printer Help


6 replies to this topic

#1 ClassicRockFan

  • Members
  • 56 posts

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 by ClassicRockFan, 07 March 2014 - 10:15 PM.


#2 CometWolf

  • Members
  • 1,283 posts

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.

#3 ClassicRockFan

  • Members
  • 56 posts

Posted 08 March 2014 - 12:25 AM

View PostCometWolf, on 07 March 2014 - 11:48 PM, said:

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 by ClassicRockFan, 08 March 2014 - 12:26 AM.


#4 CometWolf

  • Members
  • 1,283 posts

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

#5 ClassicRockFan

  • Members
  • 56 posts

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 by ClassicRockFan, 08 March 2014 - 01:52 AM.


#6 CometWolf

  • Members
  • 1,283 posts

Posted 08 March 2014 - 02:04 AM

View PostClassicRockFan, on 08 March 2014 - 01:50 AM, said:

I didn't realize that none was a syntax.
Im saying it's not.

#7 ClassicRockFan

  • Members
  • 56 posts

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 by ClassicRockFan, 08 March 2014 - 05:18 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users