CC: Tweaked

CC: Tweaked

42M Downloads

pcall doesnt stop the script from crashing

C4PTRAMPAGE opened this issue ยท 3 comments

commented

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

commented

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!")
commented

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.

commented

right so its just one of tweak's many unnecessary changes

No, this is a base Lua thing. CC:T tries to stay as true to Lua as possible and this behavior has never changed.