generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Is it popular to use the _G function like this?:

Previous Thread :: Next Thread 
EMAN381 is not online. 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 is not online. 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
JulienDethurens is not online. JulienDethurens
Joined: 11 Jun 2009
Total Posts: 11046
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
JulienDethurens is not online. JulienDethurens
Joined: 11 Jun 2009
Total Posts: 11046
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 is not online. 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
JulienDethurens is not online. JulienDethurens
Joined: 11 Jun 2009
Total Posts: 11046
22 May 2012 04:35 PM
I prefer to use this:

function _G.Foo(arg1, arg2)
print("Bar")
end
Report Abuse
SN0X is not online. 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
JulienDethurens is not online. JulienDethurens
Joined: 11 Jun 2009
Total Posts: 11046
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 is not online. 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 is not online. LPGhatguy
Forum Moderator
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 is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image