koen500
|
  |
| Joined: 23 Feb 2011 |
| Total Posts: 2277 |
|
|
| 03 Dec 2013 09:04 AM |
Sorry of that first one, I didn't realised I blocked it.
When I do this it errors: pcall(function() Object[2](Player, Message) end)
When I do this, it doesn't: Object[2](Player, Message)
What am I doing wrong? |
|
|
| Report Abuse |
|
|
einsteinK
|
  |
| Joined: 22 May 2011 |
| Total Posts: 1015 |
|
|
| 03 Dec 2013 09:11 AM |
| put print( in front of it so you can see the actual error :D |
|
|
| Report Abuse |
|
|
koen500
|
  |
| Joined: 23 Feb 2011 |
| Total Posts: 2277 |
|
|
| 03 Dec 2013 09:13 AM |
| Why wouldn't it work when I use pcall? |
|
|
| Report Abuse |
|
|
einsteinK
|
  |
| Joined: 22 May 2011 |
| Total Posts: 1015 |
|
|
| 03 Dec 2013 09:17 AM |
pcall will execute the code. if the code error, pcall itself will "catch the error". thuss, pcall returns: if code worked: true if code failed: false, "ERROR"
By printing it you'll see if there was any error |
|
|
| Report Abuse |
|
|
koen500
|
  |
| Joined: 23 Feb 2011 |
| Total Posts: 2277 |
|
|
| 03 Dec 2013 09:19 AM |
| There isn't any error, because when I execute it without pcall, it works fine. |
|
|
| Report Abuse |
|
|
|
| 03 Dec 2013 09:35 AM |
| Then why not just avoid the pcall? Don't use pcall unless you absolutely have to. |
|
|
| Report Abuse |
|
|
koen500
|
  |
| Joined: 23 Feb 2011 |
| Total Posts: 2277 |
|
|
| 03 Dec 2013 09:36 AM |
| I currently do not need it, but it might be needed later on. I'll avoid it for now. |
|
|
| Report Abuse |
|
|
|
| 03 Dec 2013 09:38 AM |
It kinda falls under the 'try/catch' abuse of other languages that some programmers get into bad habits with:
You should be writing your code so it works. Wrapping it with a protective cover is not an excuse to write bad code.
Not saying you're writing bad code :P but pcall should be used only if absolutely necessary |
|
|
| Report Abuse |
|
|
koen500
|
  |
| Joined: 23 Feb 2011 |
| Total Posts: 2277 |
|
|
| 03 Dec 2013 09:41 AM |
Yhea, I was making voice commands. But I was thinking 'what if someone enters something that breaks the script? nothing would work anymore!'
So, that's why. |
|
|
| Report Abuse |
|
|
|
| 03 Dec 2013 10:41 AM |
What happens if you use this:
pcall(Object[2], Player, Message)
Just curious. I'd like to find out why that statement is erroring for you. Is your Object[2] function yielding at all? |
|
|
| Report Abuse |
|
|