Waccsadac
|
  |
| Joined: 02 Jun 2012 |
| Total Posts: 2440 |
|
|
| 16 Jan 2016 12:03 PM |
How do I do try/catch here? I cant find it on the wiki, but I find it hard to believe roblox lua doesnt have this...
|
|
|
| Report Abuse |
|
|
|
| 16 Jan 2016 12:05 PM |
pcall(f) - "f" is a function running in protected mode, it will then return a boolean telling you if your function had an error or not. This is equivalent to try/catch.
error(msg) - This is equivalent to throw, it lets you make your own error message. |
|
|
| Report Abuse |
|
|
Waccsadac
|
  |
| Joined: 02 Jun 2012 |
| Total Posts: 2440 |
|
| |
|
|
| 16 Jan 2016 12:31 PM |
| Actually, pcall returns a boolean showing whether it succeeded or not. And then, if it did, it will return the data returned by the function as second, third, etc arguments. If it didn't, it will return the error as a second argument. |
|
|
| Report Abuse |
|
|
|
| 16 Jan 2016 12:38 PM |
I'm not recommending this at all, but this is the closest I've managed to actual try/catch/finally syntax, without the loss of syntax highlighting (if I didn't care about highlighting I'd just go use loadstring and use [[]] quotes to completely eliminate the requirement of functions):
function try(tryt) return {catch = function(catcht) xpcall(tryt[1], catcht[1]) return {finally = function(finallyt) finallyt[1]() end } end, finally = function() pcall(tryt[1]) return function(finallyt) finallyt[1]() end end } end
try { function() print(i.i) end } .catch { function(err) warn(err) end } .finally { function() print("try statement finished") end } |
|
|
| Report Abuse |
|
|
| |
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
| |
|
| |
|
Waccsadac
|
  |
| Joined: 02 Jun 2012 |
| Total Posts: 2440 |
|
|
| 16 Jan 2016 11:17 PM |
| he waz talking about his t-shirt |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 16 Jan 2016 11:40 PM |
No I was talking about war's code. And war if you really don't know why your script is disgusting then I suggest relearning Lua. |
|
|
| Report Abuse |
|
|
|
| 16 Jan 2016 11:57 PM |
| What does try and catch do |
|
|
| Report Abuse |
|
|
|
| 16 Jan 2016 11:59 PM |
| I don't even think cnt knows what he is talking about |
|
|
| Report Abuse |
|
|
|
| 17 Jan 2016 12:00 AM |
| Cnt knows what he is talking about. |
|
|
| Report Abuse |
|
|
|
| 17 Jan 2016 12:02 AM |
| Yes I know I posted that for a reason |
|
|
| Report Abuse |
|
|
|
| 17 Jan 2016 07:17 PM |
| @cnt You ought to learn that people code for different reasons. You like low-level things and you code for.. Well Idek, but I prefer to code for fun. Yes I make practical stuff. Yes I made useful stuff. But mostly, I do things for fun and for the sake of curiosity. If you can't appreciate that, then you need to learn to be a bit more open-minded and learn to respect other's opinions and hobbies, even if you don't necessarily agree with them. |
|
|
| Report Abuse |
|
|
|
| 17 Jan 2016 07:21 PM |
ew functions defined inside functions
you underestimate the power of the dank side |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 17 Jan 2016 07:23 PM |
"learn to respect other's opinions and hobbies" My hobby is making fun of your crap, so why don't you respect my hobby? Or are you special and unique and too sensitive to realize that I said your code sucks, not that it was useless (albeit it's useless because xpcall is sufficient). |
|
|
| Report Abuse |
|
|
|
| 17 Jan 2016 07:46 PM |
try { function() print(i.i) end } .catch { function(err) warn(err) end } .finally { function() print("try statement finished") end }
I like this style better, as there is no need for tables being passed.
try ( function() print(i.i) end ) .catch ( function(err) warn(err) end ) .finally ( function() print("try statement finished") end ) |
|
|
| Report Abuse |
|
|
|
| 17 Jan 2016 07:46 PM |
cnt i would like to see u do better
meow |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 17 Jan 2016 07:51 PM |
xpcall
There, I did better with 10x less overhead and 10x more efficiency. |
|
|
| Report Abuse |
|
|
|
| 17 Jan 2016 07:52 PM |
| First of all, in all honesty, I don't think that's a very healthy hobby. Secondly, this is still rather childish. Most of the stuff that gets posted here is terrible, yet for some reason, you're still here. You need to accept the fact we're not all like you. Just because I code something that sucks, as you call it, doesn't mean you have to publicly call it out it just for kicks. It's a rather immature thing to do. |
|
|
| Report Abuse |
|
|
|
| 17 Jan 2016 07:55 PM |
cnt, War can script circles around you. Go find another habit, picking on someone superior than you is childish and just makes you look weak.
~Terror |
|
|
| Report Abuse |
|
|
|
| 17 Jan 2016 07:55 PM |
'cnt i would like to see u do better '
I KNOW he could do better. I'm not claiming my code is GOOD. The only problem I have is him, after time and time again, insulting my code. He does this continuously, despite the fact it's not meant for his approval. It's childish, and immature. My code doesn't have to be up to YOUR standards cnt. |
|
|
| Report Abuse |
|
|
|
| 17 Jan 2016 07:56 PM |
"cnt, War can script circles around you."
No. |
|
|
| Report Abuse |
|
|
DrHaximus
|
  |
| Joined: 22 Nov 2011 |
| Total Posts: 8410 |
|
|
| 17 Jan 2016 07:56 PM |
"cnt, War can script circles around you. Go find another habit, picking on someone superior than you is childish and just makes you look weak."
nice 34 posts, newfriend. don't assert your opinion on topics you don't know anything about :^) |
|
|
| Report Abuse |
|
|