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

Need help with making a program

Started by Roadhouse699, 08 March 2013 - 02:52 AM
Roadhouse699 #1
Posted 08 March 2013 - 03:52 AM
In the past, I've mastered a program that repeats the words "you didn't say the magic word", a password door, a calculator, and a ICBM missile launcher. But this program has had me stuck since before I made some of the other programs: a notebook. I'm trying to make it so that you can keep typing a document until you type "exit()", and then it will print the document and close the program, but it prints the page as soon as I start the program. Here's the code I'm using:

textutils.slowprint("welcome")
printer = peripheral.wrap("right")
printer.newPage()
print("type exit() to print")
while true do
local input = io.read()
if input == exit() then
   printer.endPage()
  break
else
  repeat
   printer.write()
  until string.find(input, "exit()")
end
end
  
Engineer #2
Posted 08 March 2013 - 04:18 AM
You could use:

...
until string.find(input, "exit()")

:)/>

Also use peripheral.wrap("right") instead peripheral.wrap(right)

Edit derp:


textutils.slowprint("welcome")
printer = peripheral.wrap("right")
printer.newPage()
print("type exit() to print")
while true do
   local input = io.read()
   if input == "end()" then
	   printer.endPage()
	   break
   else
	  printer.write(input) -- not sure about the printer API
   end
   sleep(0)
end
Edited on 08 March 2013 - 07:32 AM
Roadhouse699 #3
Posted 08 March 2013 - 07:55 AM
Thanks, I'll try this out.
Roadhouse699 #4
Posted 08 March 2013 - 08:08 AM
I tried this, and after I typed the first line, the computer blanked out for a few seconds and then this problem came back:
12:too long with out yielding.
remiX #5
Posted 08 March 2013 - 08:11 AM
Change
local input = io.read
to
local input = io.read()
Roadhouse699 #6
Posted 08 March 2013 - 08:16 AM
Already did. I'll update the code in the original post
Engineer #7
Posted 08 March 2013 - 08:31 AM
Change
local input = io.read
to
local input = io.read()
Derped on that, was like its now 15:30, you have to cycle 45 minutes and 16:00 you have to get there xD

Edited my post

Try my code now, hopefully it works this time :P/>
Roadhouse699 #8
Posted 08 March 2013 - 11:35 AM
IT WORKED!!!!!!!!!!!!!!! thank you!!!
I've been trying to crack this for like a month! Thanks to all you've told me, I'm so much better at programming now!