Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

What is difference between pcall and ypcall? [closed]

Asked by
yurhomi10 192
10 years ago

This question already has an answer here:

How does ypcall and pcall work?

I never really used these call's or whatever they are called, little help will be very appreciated!

Marked as Duplicate by evaera

This question has been asked before, and already has an answer. If those answers do not fully address your question, then please ask a new question here.

Why was this question closed?

1 answer

Log in to vote
1
Answered by 10 years ago

pcall() is like your try catch block for other languages, but it has problems when used when yielding coroutines (the wait() function does this).

In roblox, you will generally want to use ypcall(), as this allows yielding across coroutines (using the wait() function inside a coroutine). They are used by passing a function.

For example;

pcall(function ()
wait()
end) -- will error

ypcall(function ()
wait()
end) -- will not error

--They are used like this:

if ypcall(doSomeDangerousFunction()) == true then
someDangerousFunctionSucceeded()
end

Click here for more information on pcall().

0
I like this! though it would really help if you could please provide just one example :D. Thanks in advance. yurhomi10 192 — 10y
Ad