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: Using XPCALL?

Previous Thread :: Next Thread 
cody123454321 is not online. cody123454321
Joined: 21 Nov 2009
Total Posts: 5408
12 Jul 2012 12:40 AM
Ok so I am trying to collect the bad output of a bad script.

How would I use the XPCALL?

I read on how to do this but it said:

>> Error: (Error message here)

I didn't know whats up...

So how would I use that?
Report Abuse
nate890 is not online. nate890
Joined: 22 Nov 2008
Total Posts: 21686
12 Jul 2012 12:49 AM
you don't need to use xpcall

s,err=pcall(function() --[[code]] end)
if err then print(err) end
Report Abuse
cody123454321 is not online. cody123454321
Joined: 21 Nov 2009
Total Posts: 5408
12 Jul 2012 12:51 AM
s,?
Report Abuse
nate890 is not online. nate890
Joined: 22 Nov 2008
Total Posts: 21686
12 Jul 2012 12:52 AM
s for statis
Report Abuse
nate890 is not online. nate890
Joined: 22 Nov 2008
Total Posts: 21686
12 Jul 2012 12:53 AM
status*
Report Abuse
cody123454321 is not online. cody123454321
Joined: 21 Nov 2009
Total Posts: 5408
12 Jul 2012 12:54 AM
would err be false or true in that statement?
Report Abuse
nate890 is not online. nate890
Joined: 22 Nov 2008
Total Posts: 21686
12 Jul 2012 12:54 AM
err, for error, would be a string.
Report Abuse
cody123454321 is not online. cody123454321
Joined: 21 Nov 2009
Total Posts: 5408
12 Jul 2012 01:19 AM
err doesnt print...
Report Abuse
thecaptain97 is not online. thecaptain97
Joined: 17 Jun 2010
Total Posts: 4987
12 Jul 2012 01:22 AM
THen no error?
Report Abuse
cody123454321 is not online. cody123454321
Joined: 21 Nov 2009
Total Posts: 5408
12 Jul 2012 01:26 AM
Ok:

I want to check a function using a script maker ingame, and then printing the error out if there is one:

err = pcall(function() end)

if(err)then print(gar)

elseif(not err)then

end

I used the above with prints. It only prints true of false.
I want it to print the actual problem.
Report Abuse
cody123454321 is not online. cody123454321
Joined: 21 Nov 2009
Total Posts: 5408
12 Jul 2012 01:39 AM
OK I found out using a above thing with "s,".

I did not know that using value,value2 = ... would get the first value and the second value.

s,d = pcall(function() asd() end)
print(s)
print(d)

> false
> s,d = pcall(function() asd() end) print(d):1: attempt to call global 'asd' (a nil value)

Assuming it goes from the command line, s,d = pcall(function() asd() end) print(d) would mean its the script name.

Report Abuse
smurf279 is not online. smurf279
Joined: 15 Mar 2010
Total Posts: 6871
12 Jul 2012 01:39 AM
print(
coroutine.resume(coroutine.create(function()

--[[Code Here]]

end))
)
Report Abuse
IamAwesome777 is not online. IamAwesome777
Joined: 18 Jul 2011
Total Posts: 2640
12 Jul 2012 01:41 AM
Whats the difference betweeen pcall cand xpcall?
Report Abuse
smurf279 is not online. smurf279
Joined: 15 Mar 2010
Total Posts: 6871
12 Jul 2012 01:43 AM
xpcall lets you create your error message
Report Abuse
IamAwesome777 is not online. IamAwesome777
Joined: 18 Jul 2011
Total Posts: 2640
12 Jul 2012 01:46 AM
I thought you could do that with pcall?

if pcall(function() print("Hello") then
print("true")
else
print("false)
end


???

(I made a deliberate mistake by not adding enough brakets.)
Report Abuse
smurf279 is not online. smurf279
Joined: 15 Mar 2010
Total Posts: 6871
12 Jul 2012 01:51 AM
nope well actually that code wouldn't really work

if pcall(function() print("Hello") end) then
print("true")
else
print("false)
end


but anyways pcall gives you the actual error message from the code while xpcall allows you to create the error message if their is an error


success, error_message = pcall

success, custom_error_message = xpcall
Report Abuse
smurf279 is not online. smurf279
Joined: 15 Mar 2010
Total Posts: 6871
12 Jul 2012 01:52 AM
"(I made a deliberate mistake by not adding enough brakets.)"

oops missed that :P
Report Abuse
IamAwesome777 is not online. IamAwesome777
Joined: 18 Jul 2011
Total Posts: 2640
12 Jul 2012 01:57 AM
So, they are more or less the same, except that pcall will tell you whats wrong with the script while xpcall doesn't.

So in short, pcall is better. Right?
Report Abuse
smurf279 is not online. smurf279
Joined: 15 Mar 2010
Total Posts: 6871
12 Jul 2012 02:06 AM
Ehh like i said xpcall gives you a custom error message while pcall gives you the real error. If you want to make your error messages xpcall; if you want the orginal error pcall

EG;

function() asd() end

pcall version -> attempt to call global 'asd' (a nil value)
xpcall version -> Error - You are attempting to call a nil function. Please make sure your function is spelled/defined properly!


With xpcall you could make the error message how you want, while pcall will always give the same error message(depending on code)
Report Abuse
IamAwesome777 is not online. IamAwesome777
Joined: 18 Jul 2011
Total Posts: 2640
12 Jul 2012 02:08 AM
Ok I get it now. I can imagine you are getting frustrated :3
Report Abuse
smurf279 is not online. smurf279
Joined: 15 Mar 2010
Total Posts: 6871
12 Jul 2012 02:11 AM
nah its 12am so i really have nothing better to do than sit and answer questions :P
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