EMAN381
|
  |
| Joined: 27 Nov 2007 |
| Total Posts: 4300 |
|
|
| 22 May 2012 04:27 PM |
function _G.something(x) --code end
I've usually seen people do something like this:
_G.something = function(x) --code end
..They both work. |
|
|
| Report Abuse |
|
|
Quenty
|
  |
| Joined: 03 Sep 2009 |
| Total Posts: 9316 |
|
|
| 22 May 2012 04:29 PM |
I use the first one, because it keeps with my syntax...
Although I do...
local function _G.Something(Variable, Variable, Variable)
end
|
|
|
| Report Abuse |
|
|
|
| 22 May 2012 04:31 PM |
@Quenty
You can't do that. Otherwise, the output is going to yell at you in red text. |
|
|
| Report Abuse |
|
|
|
| 22 May 2012 04:32 PM |
You can't make a table field local. Table fields aren't variables, you just can't make them local.
It doesn't matter whether it's _G or another table, you still can't. |
|
|
| Report Abuse |
|
|
SN0X
|
  |
| Joined: 24 Oct 2011 |
| Total Posts: 7277 |
|
|
| 22 May 2012 04:33 PM |
I've never used global stuff. Never needed too.
But _G.something = function blah blah is most common. |
|
|
| Report Abuse |
|
|
|
| 22 May 2012 04:35 PM |
I prefer to use this:
function _G.Foo(arg1, arg2) print("Bar") end |
|
|
| Report Abuse |
|
|
SN0X
|
  |
| Joined: 24 Oct 2011 |
| Total Posts: 7277 |
|
|
| 22 May 2012 04:37 PM |
I'd do same as Julien.
Makes more sense.
Otherwise you're setting it as a variable twice, right?
Idk |
|
|
| Report Abuse |
|
|
|
| 22 May 2012 04:40 PM |
@SN0X
Let me quote the Lua 5.1 Reference Manual:
The statement
function f () body end
translates to
f = function () body end
The statement
function t.a.b.c.f () body end
translates to
t.a.b.c.f = function () body end
The statement
local function f () body end
translates to
local f; f = function () body end
not to
local f = function () body end
(This only makes a difference when the body of the function contains references to f.) |
|
|
| Report Abuse |
|
|
EMAN381
|
  |
| Joined: 27 Nov 2007 |
| Total Posts: 4300 |
|
|
| 22 May 2012 05:06 PM |
| Hm. I guess I was wrong about people usually doing the second choice. |
|
|
| Report Abuse |
|
|
LPGhatguy
|
  |
 |
| Joined: 27 Jun 2008 |
| Total Posts: 4725 |
|
|
| 22 May 2012 08:48 PM |
@Julien That explains so many problems I had about a year ago. Thanks. |
|
|
| Report Abuse |
|
|
Quenty
|
  |
| Joined: 03 Sep 2009 |
| Total Posts: 9316 |
|
|
| 23 May 2012 12:18 AM |
| I guess that's why my script errored. D: |
|
|
| Report Abuse |
|
|