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

[Lua][Question] Printing Programs

Started by JasonAHawkins, 20 November 2012 - 05:48 AM
JasonAHawkins #1
Posted 20 November 2012 - 06:48 AM
Is it possible to make program "1" print the text in program "2" onto a piece of paper using a printer?
bjornir90 #2
Posted 20 November 2012 - 08:04 AM
Yes, you should open program2 as a file, read it and print it :(/>/> (ask for code if needed )
remiX #3
Posted 20 November 2012 - 10:38 AM
Made a program that should work: Pastebin :(/>/>
JasonAHawkins #4
Posted 20 November 2012 - 11:35 AM
Thanks,and wow this looks complicated. I am kinda a noob to Lua.
Orwell #5
Posted 20 November 2012 - 11:41 AM
Made a program that should work: Pastebin :(/>/>
Nice :(/>/> Just wanted to say that the tC table is redundant. It's exactly the same as the colours API (except for the methods of course). You could just do colors['blue']. Not a big deal, just wanted to share this. :)/>/>
JasonAHawkins #6
Posted 20 November 2012 - 11:58 AM
Is there any simpler code for this because i would like to understand what i am writing.
Orwell #7
Posted 20 November 2012 - 12:07 PM
Is this easier for you to understand? If not, you might want to start out with something easier. :(/>/> Or ask lots of questions here. That's what we're here for. :(/>/>
I basically cut out all the color thingies. printError() is a built-in function that prints in red. :)/>/>
http://pastebin.com/LWCJfR9X
remiX #8
Posted 21 November 2012 - 01:59 AM
Nice :(/>/> Just wanted to say that the tC table is redundant. It's exactly the same as the colours API (except for the methods of course). You could just do colors['blue']. Not a big deal, just wanted to share this. :)/>/>

Would this work?


function pC(col, text)
    term.setTextColour(colours[col])
    print(text)
end

pC("red", "Will this text be red?")

If it does, I wasted so much time typing those numbers in :(/>/>
Orwell #9
Posted 21 November 2012 - 02:19 AM
Nice :)/>/> Just wanted to say that the tC table is redundant. It's exactly the same as the colours API (except for the methods of course). You could just do colors['blue']. Not a big deal, just wanted to share this. :)/>/>

Would this work?


function pC(col, text)
	term.setTextColour(colours[col])
	print(text)
end

pC("red", "Will this text be red?")

If it does, I wasted so much time typing those numbers in :(/>/>
Yes, that would work. :)/>/> Sorry… :(/>/>
remiX #10
Posted 21 November 2012 - 02:32 AM
Nice :)/>/> Just wanted to say that the tC table is redundant. It's exactly the same as the colours API (except for the methods of course). You could just do colors['blue']. Not a big deal, just wanted to share this. :)/>/>

Would this work?


function pC(col, text)
	term.setTextColour(colours[col])
	print(text)
end

pC("red", "Will this text be red?")

If it does, I wasted so much time typing those numbers in :(/>/>
Yes, that would work. :)/>/> Sorry… :)/>/>

I could have sworn I tried that though and it kept giving me the error: "number expected" hmm, might have done colours.[col] :(/>/>. Oh well, thanks for telling me so I don't waste timed next time :)/>/>

To OP: Do you want me to explain the code for you?
bjornir90 #11
Posted 21 November 2012 - 09:18 AM
Thanks,and wow this looks complicated. I am kinda a noob to Lua.
No it's simple. Really. Basically to do it fast you only need about 8 lines :(/>/> all the rest of the codes that are here is only optional but recommanded to do. It verify everything so you are sure the program will print it.
seerhan #12
Posted 17 December 2012 - 01:49 PM
Is this easier for you to understand? If not, you might want to start out with something easier. :mellow:/>/> Or ask lots of questions here. That's what we're here for. :)/>/>
I basically cut out all the color thingies. printError() is a built-in function that prints in red. :)/>/>
http://pastebin.com/LWCJfR9X
So, I'm pretty new to this, but I can tell what's generally going on with the code. I do need to ask, though: what sort of format would a file have to be in for this program to print it? How does it know when to move onto the next page, for example. Just a little example of a page would be perfect, thanks