Jump to content

ComputerCraft problem with a program


Recommended Posts

Hey guys,

I just scipted a little program for print Texts on paper. My problem was that the read() command doesn't start a new line when the line is full, so I tried to fix that with the parallel API.

In the following screenshots you can see my code and the error message. I hope you can help me fix that^^





Link to comment
Share on other sites

Hey, I'll try my best helping you ! It crashes because what your function typeToPaper() does is wait the user to write something and hit enter, it does not write on the paper, then it returns true (you will not be able to get the text entered, because your variable is local so it can only be accessed in the function, and its content will be deleted after the return), while your checkPosition() function loops until there are too many lines written on the paper, but nothing is never written on it, so it never stops, and the error is triggered because it loops for too long. The only way you could do exactly what you event is through the event system, your program waits until the user hits a char key for example ( os.pullEvent("char") ), then write the char on the screen (and on the paper if you want your program to work like a typewriter). But you could go further and wait for the user not only to hit a char key, but a key ( os.pullEvent("key") ), and treat the key pressed with the Keys API so you can do carriage returns, tabulations, and cool stuff like that. In facts, this is exactly how the read() function works ! Hope this will help, I will be happy to write an example program if you need one. If someone know how to write on a new line on this forum, tell me, I'm sorry this must be a pain to read me, and I have a bad English

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...