Yoo thats so cool can u send me a code sample of it?
of xpcall or opcall?
Both pls sorry to disturb u i just want to learn it.
Oh so if you want xpcall, read this
Read the xpcall section
Tysm so xpcall is like the .try and .catch in javascript. Nice
Thank you for appreciating my resource!
Oh yeah and for opcall read this code sample
function opcall(functiontorun, functiontorunonsuccess, functiontorunonerror)
local result
-- running function
local success,err = pcall(function()
result = functiontorun()
end)
if success then
-- worked
print("the result is:", result)
functiontorunonsuccess(result)
else
-- failed
functiontorunonerror(err)
end
return success,err
end
-- calling function
local succ, err = opcall(
function()
return 1 + 2 == 5
end,
function(result)
print(result)
end,
function(err)
print(err)
end
)
Made it so you can return and get the result and also removed some code that isn’t needed
cool, but ireally prefer removing print, thanks anyway
looks nice! code is great as well. good job
UPDATE
Removed an unnessecary part in the opcall.
also i noticed that the function will be underlined red but it will still work
proof
thanks
It seems like someone finally made this and released it to the public, I didn’t make a post about mine :v
Ig nice code. I really could’ve used assert lol.
Also, assert does huge memory consuming. I suggest you do the disgusting ifs.
I made a version of this but with ternary.(the fake ternary)
function opcall(functiontorun,functionerr,function success)
local success,err = pcall(function()
functiontorun = functiontorun()
end
success == true and functionsuccess(success) or functionerr(err)
end
I really like one liners, but I didn’t test it yet so I don’t think it work
Can I get the source of this information? Never heard of assert
being memory intensive.
Here.
Guess I have a lot of work to do then.
eh not really. just replace assert with if.
local function assert(value, errorMessage)
return value or error(errorMessage or "assertion failed!", 2)
end