|
| 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
|
  |
| 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 |
|
|
| |
|
nate890
|
  |
| Joined: 22 Nov 2008 |
| Total Posts: 21686 |
|
| |
|
nate890
|
  |
| Joined: 22 Nov 2008 |
| Total Posts: 21686 |
|
| |
|
|
| 12 Jul 2012 12:54 AM |
| would err be false or true in that statement? |
|
|
| Report Abuse |
|
|
nate890
|
  |
| Joined: 22 Nov 2008 |
| Total Posts: 21686 |
|
|
| 12 Jul 2012 12:54 AM |
| err, for error, would be a string. |
|
|
| Report Abuse |
|
|
| |
|
| |
|
|
| 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 |
|
|
|
| 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
|
  |
| Joined: 15 Mar 2010 |
| Total Posts: 6871 |
|
|
| 12 Jul 2012 01:39 AM |
print( coroutine.resume(coroutine.create(function()
--[[Code Here]]
end)) ) |
|
|
| Report Abuse |
|
|
|
| 12 Jul 2012 01:41 AM |
| Whats the difference betweeen pcall cand xpcall? |
|
|
| Report Abuse |
|
|
smurf279
|
  |
| Joined: 15 Mar 2010 |
| Total Posts: 6871 |
|
|
| 12 Jul 2012 01:43 AM |
| xpcall lets you create your error message |
|
|
| Report Abuse |
|
|
|
| 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
|
  |
| 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
|
  |
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 12 Jul 2012 02:08 AM |
| Ok I get it now. I can imagine you are getting frustrated :3 |
|
|
| Report Abuse |
|
|
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 |
|
|