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

three questions

Started by 0099, 29 June 2013 - 02:21 PM
0099 #1
Posted 29 June 2013 - 04:21 PM
I have a program that gets a file from rednet and runs it with pcall(function() dofile("file") end). It has the security system that stops program with error() in case of illegal action from program of if user presses F1 button.

1. One error (if user presses F1, error("break key pressed")), instead of sending message to pcall(), prints "break key pressed Press any key to continue" and after pressing any key shuts computer down. Why?

2. term.write() changed into new function: it calls old term.write and saves text into special variable. But: if program uses print(), there aren't newline characters in save variable. If program uses directly term.write with newline character manually added, there aren't newlines at the display, only "?". Why?

3. Security system also includes detection of error() function modifying. But: if program changes error() into other function, or nil, or anything, and at the next linecalls it, it calls the original function! Why?

Full code: http://pastebin.com/Ws1BKVpm

Sorry for my english if I spelled something wrong
Lyqyd #2
Posted 30 June 2013 - 02:14 AM
Split into new topic.

2. Because term.write() doesn't handle newline characters, write() does. print() calls write(), which breaks up strings as necessary and calls term.write() and term.setCursorPos(), among others, to draw correctly to the screen.
0099 #3
Posted 30 June 2013 - 02:01 PM
2. Because term.write() doesn't handle newline characters, write() does. print() calls write(), which breaks up strings as necessary and calls term.write() and term.setCursorPos(), among others, to draw correctly to the screen.
I didn't know that term.write() and _G.write() are different functions. Thanks, I will install saving system to term.setCursorPos() too.