Hello! This is my first resource, so please make constructive criticism instead of “Hey, this resource is useless.”
What does this function do?
It’s meant to save your time, it’s basically xpcall but with the success argument, I hope you enjoy it!
function opcall(functiontorun, functiontorunonsuccess, functiontorunonerror)
-- running function
local success,err = pcall(function()
functiontorun = functiontorun()
end)
if success then
functiontorunonsuccess(functiontorun)
else
-- failed
functiontorunonerror(err)
end
return success,err
end -- kinda modified by @FelixProfit.
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
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