Jump to content

ComputerCraft problem with a program


Alzheimer1992
 Share

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^^

kgcthuvq.png

4ihvl9ep.png

zqku755m.png

cuy34el9.png

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...