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

[LUA] [Question] printing

Started by dragonherald, 08 March 2013 - 11:23 AM
dragonherald #1
Posted 08 March 2013 - 12:23 PM
Hello, I was wondering if there was a command to print the text currently on the screen. Like say I send a message via rednet to another computer is there a way I can print the message out? Thank you for your time and help in advance. Here's the code I got that I want to add to if it's possible.


rednet.open = ("top")
id, message = rednet.receive ()
print ("Computer".. id .."has sent us a message!")
print ("The message is...")
sleep (2)
term.clear ()
term.setCursorPos (1, 1)
print (message)
SuicidalSTDz #2
Posted 08 March 2013 - 12:36 PM
print("the message is "..massage) should work nicely. Any variables can be printed like this

Lol i typed "massage" :P/>
dragonherald #3
Posted 08 March 2013 - 12:39 PM
print("the message is "..massage) should work nicely. Any variables can be printed like this

Sorry, I don't think I explained myself correctly is there a way to print it to an attached printer? instead of to the computer. I'm talking like physical (in a digital world anyway) paper with ink on it.
SuicidalSTDz #4
Posted 08 March 2013 - 12:41 PM
Well i would go to the wiki and look at the printer api. Im on my phone so i cannot link you there.
dragonherald #5
Posted 08 March 2013 - 12:54 PM
Okay, thank you.
oeed #6
Posted 08 March 2013 - 12:56 PM
Now, I haven't tested this and you'll want to add crash prevention, but basically:


printer = peripheral.wrap("left") -- wrap the printer
printer.write(message)

Take a look at the Printer (API)
dragonherald #7
Posted 08 March 2013 - 01:04 PM
Now, I haven't tested this and you'll want to add crash prevention, but basically:


printer = peripheral.wrap("left") -- wrap the printer
printer.write(message)

Take a look at the Printer (API)

cool, thank you. I'll do some testing with this

Did some testing. You need to start the printer with


printer.peripheral.wrap ("left")
printer.newPage () -- loads the paper to be written
printer.write (message) -- does the actual printing
printer.endPage () -- outputs page to the tray.

Eventually I came up with the code


rednet.open ("top")
printer.peripheral.wrap ("left")
id, message - rednet.receive ()
print ("Computer".. id .."has sent us a message!")
print ("The message is...")
sleep (2)
term.clear ()
term.setCursorPos (1, 1)
print (message)
printer.newPage ()
printer.write (message)
printer.endPage ()
sleep(0)

You can also set this up so it will continuously print any message going through your section of rednet. I imagine you could use sets of computers and modems sending messages to each other and monitor a large area. But, currently the code I pasted is more of an "email" type system where you can keep the documents.

Edit: Ran in to another issue. It will only print one line of text to the paper. I'll be messing around with this for a couple of hours at least and I got school tomorrow so I'll get back to this thread then.
oeed #8
Posted 08 March 2013 - 01:36 PM
–snip snip–

Edit: Ran in to another issue. It will only print one line of text to the paper. I'll be messing around with this for a couple of hours at least and I got school tomorrow so I'll get back to this thread then.

The reason it is only printing one line per-page is because you're calling these every time. Only run that when needed.

printer.newPage () -- loads the paper to be written
printer.endPage () -- outputs page to the tray.