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 » Scripting Helpers
Home Search
 

Re: Pcall and Ypcall

Previous Thread :: Next Thread 
error9999 is not online. error9999
Joined: 05 Sep 2009
Total Posts: 1593
26 May 2014 12:08 AM
where could I use them for?
I know it has something to do with errors but Idk how to use it.
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
26 May 2014 12:11 AM
ypcall(function()
print("hi")
LOLERROR()
print("hey")
end)

print("hello")


output
hi
hello


Basically if it errors inside the pcall, it will not stop the script from running after that

the difference between pcall and ypcall

pcall(function()
wait(1)
end) -- breaks because you can't use wait inside pcall

ypcall(function()
wait(1)
end) --works fine
Report Abuse
islandmaker2012 is not online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
26 May 2014 12:13 AM
what, you cant use wait in pcall? whattttttttttttttt
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
26 May 2014 12:19 AM
In Lua 5.2 you can, but not 5.1 so Roblox created "ypcall" and used a hack to allow it to work
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
26 May 2014 12:19 AM
Thats how it used to be
Its also what the wiki still says
http://wiki.roblox.com/index.php/Function_Dump/Roblox_Specific_Functions#ypcall

But apparently, they changed it
Report Abuse
error9999 is not online. error9999
Joined: 05 Sep 2009
Total Posts: 1593
26 May 2014 12:29 AM
so if you think there is an error in your script, I've to use ypcall to run the script?
Report Abuse
islandmaker2012 is not online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
26 May 2014 12:32 AM
its not really good practice to use it, you could just use if statements

but instead of looking for the humanoid

HP = 5
function Touched(Hit)
ypcall(function() Hit.Parent.Humanoid.Health = HP end)
end
script.Parent.Touched:connect(Touched)
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
26 May 2014 12:33 AM
No, because as seen in my example

pcall(function()
print("hi")
error()
print("hey")
end)

Once it errors, everything in the pcall stops running (Because the function returned)


So you should not put the whole script in it
Here is a example of how it can be useful
Both decals and parts have a .Transparency, and say I want to hide both
I could say :IsA("BasePart") or :IsA("Decal"), but I prefer to do it like this


function Hide(Object)
for _, x in pairs (Object:GetChildren()) do
ypcall(function()
x.Transparency = 1
end)
Hide(x)
end
end

Hide(Game.Players.Player1.Character)
Report Abuse
twerq is not online. twerq
Joined: 08 Jun 2013
Total Posts: 1057
26 May 2014 12:39 AM
[ Content Deleted ]
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
26 May 2014 12:40 AM
Yes, or if you did this

function Hide(Object)
for _, x in pairs (Object:GetChildren()) do
ypcall(function()
x.Transparency = 1
end)
Hide(x)
end
end

Hide(Workspace)

It would make the whole game invisible.
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
26 May 2014 12:41 AM
Its much more useful for unknown errors than what I just did with it though

Maybe like pcall the command about to be ran in a admin script so if something does go wrong it doesn't break the whole admin script
Report Abuse
twerq is not online. twerq
Joined: 08 Jun 2013
Total Posts: 1057
26 May 2014 12:42 AM
[ Content Deleted ]
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
26 May 2014 12:47 AM
Because you don't always know when it'll error
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
26 May 2014 12:58 AM
Using IsA method is about 100x faster than pcall (not literally 100x, but pcall is slow)
Report Abuse
islandmaker2012 is not online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
26 May 2014 01:02 AM
^true, but some ppl are lazy ^_^
Report Abuse
JoshuaKempfert is not online. JoshuaKempfert
Joined: 16 Feb 2013
Total Posts: 2407
26 May 2014 01:04 AM
Well being lazy could cost you a huge amount of performance in your game e.e
Report Abuse
islandmaker2012 is not online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
26 May 2014 01:05 AM
@Josh
also true, but if you have "if hit.Parent:FindFirstChild("Humanoid") then" like 100 times in your script and your almost done your script and you have 1 more function, your like.."f it"

pcall(function() h.Parent.Humanoid:TakeDamage(Dmg) end)
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
26 May 2014 01:10 AM
nah pcall(function() end) is pretty long also.
If you're that lazy you probably shouldn't be scripting
Report Abuse
islandmaker2012 is not online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
26 May 2014 01:12 AM
example code XD

if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Humanoid:FindFirstChild("Killer") then
if game.Players:FindFirstChild(hit.Parent.Killer.Value) then
p = game.Players[hit.Parent.Killer.Value]
--stuff
end
end

or

pcall(function()
p = game.Players[hit.Parent.Humanoid.Killer.Value]
--stuff
end)
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
26 May 2014 01:15 AM
Yes but even then, the FindFirstChild method is cheap so it's still possible that it might be faster. And can be even further sped up
Report Abuse
FreeScriptMaker is not online. FreeScriptMaker
Joined: 29 Nov 2013
Total Posts: 2275
26 May 2014 01:17 AM
if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Humanoid:FindFirstChild("Killer") then
local p = hit.Parent.Killer.Value

if p then
--code
end
end
Report Abuse
islandmaker2012 is not online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
26 May 2014 01:17 AM
but if you just wrote 700 lines of code after like hours of stuff, your brain is ready to explode, you just feel like not putting all the ifs there, and just finish the code
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
26 May 2014 01:18 AM
That means it is time to take a break lol
Report Abuse
FreeScriptMaker is not online. FreeScriptMaker
Joined: 29 Nov 2013
Total Posts: 2275
26 May 2014 01:20 AM
If you've been scripting for so long that you're ready to make your code inefficient just to get it done with then you should take a break.
Report Abuse
islandmaker2012 is not online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
26 May 2014 01:21 AM
yeah, that's when I go and hit my head against the wall for a good 10 minutes
or until I fall asleep

XD
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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