radar001
|
  |
| Joined: 04 Sep 2011 |
| Total Posts: 718 |
|
|
| 23 Jun 2015 05:34 PM |
Why does roblox lua return nil then err? In traditional Lua this is a non-issue, as it can be evaded with a simple if statement, but what can loosely be called the Roblox lua "interpreter" complains every time a value come up nil. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 23 Jun 2015 05:37 PM |
A lot of things return nil, err. Not only some Roblox stuff. It's not an issue on Roblox Lua either. |
|
|
| Report Abuse |
|
|
radar001
|
  |
| Joined: 04 Sep 2011 |
| Total Posts: 718 |
|
|
| 23 Jun 2015 05:38 PM |
| @Cnt, it sure seems that way a lot of times though |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 23 Jun 2015 05:40 PM |
| Can you give an example, because I return nil, err a lot (bad habit, but whatever) when I want to tell the caller of the function that something went wrong and I had never had any sort of problem. |
|
|
| Report Abuse |
|
|
lordrambo
|
  |
| Joined: 16 Jun 2009 |
| Total Posts: 20628 |
|
|
| 23 Jun 2015 05:41 PM |
Uhh?
local var = nil is fine, if that's what you mean. var + 1 or otherwise treating var like anything beside nil is of course not fine.
If that's not what you mean I'm going to ask you to try to explain yourself better. |
|
|
| Report Abuse |
|
|
radar001
|
  |
| Joined: 04 Sep 2011 |
| Total Posts: 718 |
|
|
| 23 Jun 2015 05:41 PM |
| So are all objs treated like files when they give a return value? |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 23 Jun 2015 05:42 PM |
| I'm assuming you mean Roblox objects/instances, and the way that works is Roblox spits out an error if it's not a property or a child (properties are looked up first, hence the order). Basically the 2 reasons why FindFirstChild exists. |
|
|
| Report Abuse |
|
|
lordrambo
|
  |
| Joined: 16 Jun 2009 |
| Total Posts: 20628 |
|
|
| 23 Jun 2015 05:44 PM |
"So are all objs treated like files when they give a return value?"
Objs don't "return" anything (except functions). I'm not sure if you mean the Objs that you see in the explorer or all objects. Regardless, they all have "tostring" methods to them. Every time you print something that isn't a string there is an implicit call to tostring. |
|
|
| Report Abuse |
|
|
radar001
|
  |
| Joined: 04 Sep 2011 |
| Total Posts: 718 |
|
|
| 23 Jun 2015 05:46 PM |
@Cnt, thanks
@Lord, they all return something though don't they? If it doesn't exist it returns nil and if it exists it returns a tostr of the data models name. |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
| |
|
lordrambo
|
  |
| Joined: 16 Jun 2009 |
| Total Posts: 20628 |
|
|
| 23 Jun 2015 05:48 PM |
| No, tostring returns something (it's a function). Like I said, when you print them, they are tostringed implicitly. |
|
|
| Report Abuse |
|
|
radar001
|
  |
| Joined: 04 Sep 2011 |
| Total Posts: 718 |
|
|
| 23 Jun 2015 05:49 PM |
| So its "ret val" is a ret val of another function? |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 23 Jun 2015 05:51 PM |
| Metamethods. Metamethods for days. |
|
|
| Report Abuse |
|
|