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: How do you use pcall()?

Previous Thread :: Next Thread 
mawrocks is not online. mawrocks
Joined: 27 Jun 2009
Total Posts: 25
09 Jul 2011 10:06 PM
is it pcall(function name)?

Can someone post a simple pcall so i can learn it?
Report Abuse
Shobobo99 is not online. Shobobo99
Joined: 30 Dec 2008
Total Posts: 5754
09 Jul 2011 10:07 PM
pcall(function ()
workspace.mawrocks:Remove()
end)
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
09 Jul 2011 10:08 PM
print(
pcall(function()
pppppppprint!!!! (":O")
end)
)


--> false Workspace.Script:3: '=' expected near '!'
Report Abuse
DingDong272 is not online. DingDong272
Top 100 Poster
Joined: 08 Dec 2007
Total Posts: 9860
09 Jul 2011 10:10 PM
pcall and xpcall return errors. They're useful for testing scripts that would otherwise be testable only in Play mode, where you cannot see output.
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
09 Jul 2011 10:11 PM
Don't coroutines return errors as well? And loadstring?
It's been a very long time since I've worked with loadstring, and I haven't bothered to check coroutines...
Report Abuse
DingDong272 is not online. DingDong272
Top 100 Poster
Joined: 08 Dec 2007
Total Posts: 9860
09 Jul 2011 10:12 PM
Coroutines don't from my experience working with them, and I've never worked with loadstring.
Report Abuse
mawrocks is not online. mawrocks
Joined: 27 Jun 2009
Total Posts: 25
09 Jul 2011 10:13 PM
so you put the whole function in the parentheses? Okay, because it helps out with function debugging :333
Report Abuse
ElectricAxel is not online. ElectricAxel
Joined: 15 May 2009
Total Posts: 16239
09 Jul 2011 10:14 PM
Yeah, people use coroutines in sb because they don't break with a wait in them yet they still return errors without breaking the script.
Report Abuse
DingDong272 is not online. DingDong272
Top 100 Poster
Joined: 08 Dec 2007
Total Posts: 9860
09 Jul 2011 10:14 PM
You can also call just the function name, like this:

function pcallTest()
ppprint("!!!")
end

pcall(pcallTest())
Report Abuse
ElectricAxel is not online. ElectricAxel
Joined: 15 May 2009
Total Posts: 16239
09 Jul 2011 10:15 PM
I thought it was pcall(pcallTest) with no parenthesis ... :P Also, you can pass arguments:

pcall(foo, a, b)
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
09 Jul 2011 10:16 PM
"so you put the whole function in the parentheses? Okay, because it helps out with function debugging :333"

Yes and no.


function a(part)
print( part.NumberValueOOOO )
end

print( pcall(a, workspace.Part) )
--> false NumberValueOOOO is not a valid member of Part

print( pcall(function() a(workspace.Part) end) )
--> false NumberValueOOOO is not a valid member of Part


Just make sure the first argument is a function. All other arguments are passed on to the function.

Also, you cannot yield the current thread within the function when using pcall.
Report Abuse
DingDong272 is not online. DingDong272
Top 100 Poster
Joined: 08 Dec 2007
Total Posts: 9860
09 Jul 2011 10:16 PM
That's right, you pass the arguments of the function you call as arguments of pcall. Thanks for reminding me.
Report Abuse
chikenugget is not online. chikenugget
Joined: 09 May 2009
Total Posts: 2552
09 Jul 2011 10:24 PM
Does pcall() automatically print itself, just wondering...
Report Abuse
ElectricAxel is not online. ElectricAxel
Joined: 15 May 2009
Total Posts: 16239
09 Jul 2011 10:26 PM
No, you have to print it, it just returns a string with the error.
Report Abuse
chikenugget is not online. chikenugget
Joined: 09 May 2009
Total Posts: 2552
09 Jul 2011 10:27 PM
Mawrocks is me, I was forced to use my bros acc for a sec...

i tried this and it said
Sat Jul 09 22:26:08 2011 - Workspace.mainstoof.Tele2:11: bad argument #1 to 'pcall' (value expected)


function tele2(plyr)
if game.Players.NumPlayers > 2 then
if _G["Tele"] == true then
plyr.Character.Torso.CFrame = CFrame.new(Vector3.new(script.Parent.Vector3Value.Value))
end
end
end

game.Players.PlayerAdded:connect(tele2)

pcall(tele2(plyr))
Report Abuse
ElectricAxel is not online. ElectricAxel
Joined: 15 May 2009
Total Posts: 16239
09 Jul 2011 10:28 PM
pcall(tele2, plyr) you put the function's name with no parenthesis, and then the arguments.
Report Abuse
cool12309 is not online. cool12309
Joined: 21 Sep 2008
Total Posts: 1442
09 Jul 2011 10:44 PM
As agent said, I think, you can't use wait()'s (or the like) while in pcall(). It just breaks the pcall.

Which is ironic because pcall is supposed to never break.

~Waits for disproving statement
Report Abuse
chikenugget is not online. chikenugget
Joined: 09 May 2009
Total Posts: 2552
09 Jul 2011 10:44 PM
So if it prints 'true' it works fine?
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
09 Jul 2011 10:46 PM
"As agent said, I think, you can't use wait()'s (or the like) while in pcall(). It just breaks the pcall."

+1



"So if it prints 'true' it works fine?"

+1
Report Abuse
cool12309 is not online. cool12309
Joined: 21 Sep 2008
Total Posts: 1442
09 Jul 2011 10:48 PM
My first internet point, given by AgentFirefox.

I FEEL SPECIAL <3
Report Abuse
chikenugget is not online. chikenugget
Joined: 09 May 2009
Total Posts: 2552
09 Jul 2011 10:52 PM
I got an AFF point!

*does pokemon raise hand in air in triumph*
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
09 Jul 2011 10:56 PM
Now, I command thee help me.

http://www.roblox.com/Forum/ShowPost.aspx?PostID=50261792

If you can explain it, I'll give you 5 internets (Ozzypig gave those to me a couple days ago, but I don't absolutely need them).
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