Opcall - first resource

May i ask, whats xpcall? Whats the use ofmxpcall?

It’s pcall but it gives you an argument which is a function , and it runs it when it errors.

Opcall is xpcall but with the success arg, and I also believe it’s faster than xpcall as it’s using pcall.

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

1 Like

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

1 Like

cool, but ireally prefer removing print, thanks anyway

1 Like

looks nice! code is great as well. good job :slight_smile:

1 Like

UPDATE

Removed an unnessecary part in the opcall.

also i noticed that the function will be underlined red but it will still work


proof
image
thanks

It seems like someone finally made this and released it to the public, I didn’t make a post about mine :v

1 Like

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.

1 Like

Guess I have a lot of work to do then.

1 Like