pcall doesnt stop the script from crashing
C4PTRAMPAGE opened this issue ยท 3 comments
Minecraft Version
1.20.x
Version
1.108.4
Details
last time i used cc, calling functions this way stopped scripts from crashing and now it doesn't and according to everything i've read about cc tweaked this should still do the job.
local ok = pcall(term.write())
if ok then
--work.
else
--be silent!
end
This is not a bug. pcall
expects the function object, not for you to call the function. What you're doing currently is calling the function, then passing the return value to pcall
.
What you want is the following:
local ok, error_message = pcall(term.write)
Notice the lack of ()
after term.write
. This is because we want to pass the function as a variable, not call the function.
If you want to add arguments,
local ok, error_message = pcall(term.write, "Hello world!")
right so its just one of tweak's many unnecessary changes, because i remember that used to work exactly as i wrote it in cc.