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

Printers + Program... can it work?

Started by xXAdamXx, 21 May 2014 - 12:28 AM
xXAdamXx #1
Posted 21 May 2014 - 02:28 AM
Hi,
So im a newb to lua, and Im making a comments feature that will print to the specified printer (Back printer.)
The not will travel by hoppers, to the chest.

Here is my code.
os.pullEvent = os.pullEventRaw

monitor.write("Bla Bla Bla") –not shown for Obvious Reasons. also, How do i seperate these 2?
print("NONOnon") –Again, Not shown
print("This is the last one")

local input == ANN then
term.clear()
local input = read()

print(""..input) –I want this to be Where it prints!
Lyqyd #2
Posted 21 May 2014 - 03:43 AM
I removed the unnecessary poll.
awsmazinggenius #3
Posted 21 May 2014 - 05:09 AM
Provide more context. How are your peripherals set up? Whee is your printer. What is with the monitor? Why do you have "then" after your variable decleration?
BlockSmith #4
Posted 21 May 2014 - 08:04 AM
Let me try to break this down a little and see if my understanding is correct. If not, what I see may enlighten you on where you're code is going wrong. There isn't much here to go off of.
os.pullEvent = os.pullEventRaw –To keep people from terminating the program

monitor.write("Bla Bla Bla") –not shown for Obvious Reasons. also, How do i seperate these 2?

– What are you trying to separate? There is a monitor.write() function with a string variable used as parameters.

print("NONOnon") –Again, Not shown –Print function with a string parameter
print("This is the last one") –Print function with a string parameter

local input == ANN then –This is an improper conditional. This line says, "local input is equal to ANN" with an unneeded then at the end. Also, unless "ANN" is declared somewhere else that you haven't posted, then it is an undeclared variable and is equal to nil

term.clear() – this clears the screen
local input = read() – this gets input from the user and stores it in the variable "input"

print(""..input) –I want this to be Where it prints! – This should print an empty string and concatenate it with the "input" variable

I hope what I've translated here helps. If not please give a more detailed description of your purpose and code.
xXAdamXx #5
Posted 21 May 2014 - 11:31 PM
1. never mind for the line seperation.
2. I got rid of the improper local input == ANN

Also, the purpouse is to be like a feedback machine that prints out the feedback when created.

Also, The Code is now like this.

os.pullEvent = os.pullEventRaw –To keep people from terminating the program
printer = peripheral.wrap(back) –To let the computer know where the printer is
Print("Bla Bla Bla") –Unmeasured text.
sleep(3) – to notify the user.
term.clear() – this clears the screen
local input = read() – allows User input and storeds it in "input"
printer.write(input) – this is my problem! the nil error happens here!

Yet it still gives me a nil error. I have checked the wiki, and im sure i have written correct.
BlockSmith #6
Posted 22 May 2014 - 05:46 AM
If you look here –> http://computercraft.info/wiki/Printer.write you'll see that you need to tell the printer to start and end the page you wish to print.

This quick code I wrote took my input and put it on the paper perfectly fine. However, I have not tested this for any string longer than "Hello World". So this should be a good base for you to get started.


printer = peripheral.wrap("right")
print("Please input the text to be printed:")
print()
input = read()
printer.newPage()
printer.write(input)
printer.endPage()
xXAdamXx #7
Posted 22 May 2014 - 01:09 PM
thanks blocksmith!
BlockSmith #8
Posted 22 May 2014 - 08:35 PM
You're welcome!