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
|
  |
| Joined: 30 Dec 2008 |
| Total Posts: 5754 |
|
|
| 09 Jul 2011 10:07 PM |
pcall(function () workspace.mawrocks:Remove() end) |
|
|
| Report Abuse |
|
|
|
| 09 Jul 2011 10:08 PM |
print( pcall(function() pppppppprint!!!! (":O") end) )
--> false Workspace.Script:3: '=' expected near '!' |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 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 |
|
|
|
| 09 Jul 2011 10:14 PM |
You can also call just the function name, like this:
function pcallTest() ppprint("!!!") end
pcall(pcallTest()) |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 09 Jul 2011 10:24 PM |
| Does pcall() automatically print itself, just wondering... |
|
|
| Report Abuse |
|
|
|
| 09 Jul 2011 10:26 PM |
| No, you have to print it, it just returns a string with the error. |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 09 Jul 2011 10:44 PM |
| So if it prints 'true' it works fine? |
|
|
| Report Abuse |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 09 Jul 2011 10:52 PM |
I got an AFF point!
*does pokemon raise hand in air in triumph* |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|