generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: pcall?

Previous Thread :: Next Thread 
Kasumo is not online. Kasumo
Joined: 22 Mar 2013
Total Posts: 2467
07 Dec 2016 07:11 PM
does pcall allow the script to continue even if there's an error in a line?
Report Abuse
FlamedSkull is not online. FlamedSkull
Joined: 23 May 2009
Total Posts: 1379
07 Dec 2016 07:17 PM
Yes


Report Abuse
Lykaon is not online. Lykaon
Joined: 27 Oct 2014
Total Posts: 784
07 Dec 2016 07:18 PM
its meant for you to handle errors while at the same time prevent the entire script from being rerumued.


Epix Incorporated Agent Lykaon || #game.Players.PlayerAdded:connect(function(plr) plr:Kick() end)
Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
07 Dec 2016 07:21 PM
Not really, it just gives you the ability to determine whether a function was successful or not. If it ends in error, its first argument will be false.

For example, a random situation...

for i = 1,5 do
local part = Instance.new("Part",workspace)
part.Name = i
end
-- we have 5 parts named 1-5 in the workspace

function Func()
local pick = math.random(1,10)
workspace.Pick.BrickColor = BrickColor.random()
end

while wait(1) do
success, message = pcall(Func)
if success then
print("Success!")
else
print("Failure!",message)
end
end




Report Abuse
Lykaon is not online. Lykaon
Joined: 27 Oct 2014
Total Posts: 784
07 Dec 2016 07:22 PM
^ i think thats what i meant by "handle errors" but ok.

i see how it is. :(


Epix Incorporated Agent Lykaon || #game.Players.PlayerAdded:connect(function(plr) plr:Kick() end)
Report Abuse
Kasumo is not online. Kasumo
Joined: 22 Mar 2013
Total Posts: 2467
07 Dec 2016 07:26 PM
but if a function isn't successful won't you just get output
Report Abuse
Lykaon is not online. Lykaon
Joined: 27 Oct 2014
Total Posts: 784
07 Dec 2016 07:29 PM
well if it isnt successful, it just errors, but pcall prevents an entire script from being pooped on


Epix Incorporated Agent Lykaon || #game.Players.PlayerAdded:connect(function(plr) plr:Kick() end)
Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
07 Dec 2016 07:37 PM
No, pcall returns whether a script errored or not.
It does not protect the function.

However, to leverage pcall to protect your function (for stuff like data storing) you would put that pcall in a LOOP, and then run the function over and over until pcall returns true (i.e. the function was successful)


Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
07 Dec 2016 07:38 PM
oops
*pcall returns whether a -FUNCTION- errored or not.


Report Abuse
i_Ja is not online. i_Ja
Joined: 06 Apr 2014
Total Posts: 9297
07 Dec 2016 07:56 PM
pcall stops the script from breaking. pcall lets you print the error instead of making the entire script break.

~Add 5k+ Posts~ {Previous Names: ContentCrown, i_Movie, SurfaceLight}
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image