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 » Scripting Helpers
Home Search
 

Re: What exactly are Global functions?

Previous Thread :: Next Thread 
ked2000 is not online. ked2000
Joined: 10 Jul 2011
Total Posts: 1059
04 Nov 2013 10:08 PM
NOTE: I am not very experienced with Roblox LUA, so I may ask "stupid" questions.

I have been staring at the Roblox Wiki page, directly where Global Functions is located and I am completely confused. Ok, so I know "_G" is a variable for the global table, I get that. But what do they mean by, "Global functions are functions that are accessible in all environments and threads." What?

I am so confused right now. Also, what are the capabilities of using Global functions? And how can you create a script that utilizes global functions?
Report Abuse
Scriptural is not online. Scriptural
Joined: 06 Sep 2013
Total Posts: 2979
04 Nov 2013 10:09 PM
In one script
_G.Hello = function(stuff)
print(stuff)
end


In another script (That isn't local, or if the first script was local, that is)

_G.Hell("lol")

Output : lol
Report Abuse
Scriptural is not online. Scriptural
Joined: 06 Sep 2013
Total Posts: 2979
04 Nov 2013 10:10 PM
_G.Hello("lol")*
Report Abuse
ToxicDominator is not online. ToxicDominator
Joined: 24 Oct 2013
Total Posts: 8373
04 Nov 2013 10:12 PM
Global functions are functions that either start with:

_G
shared

And can be used cross-script.

_G.print=function(string)
print(string);
end;

--OR--

shared.print=function(string)
print(string);
end;

Then:

_G.print("hi");

--OR--

shared.print("hi");
Report Abuse
ked2000 is not online. ked2000
Joined: 10 Jul 2011
Total Posts: 1059
04 Nov 2013 10:13 PM
@Scriptural

So, global functions can interact with scripts of the same class(scripts or localscripts) as long as the global table references them?
Report Abuse
Scriptural is not online. Scriptural
Joined: 06 Sep 2013
Total Posts: 2979
04 Nov 2013 10:14 PM
Right
Also in local scripts, its local to that player, not all local scripts, just local scripts on that players client
Report Abuse
ked2000 is not online. ked2000
Joined: 10 Jul 2011
Total Posts: 1059
04 Nov 2013 10:16 PM
I see...

Oh and by the way, thanks Toxic for giving me another example.
Report Abuse
Scriptural is not online. Scriptural
Joined: 06 Sep 2013
Total Posts: 2979
04 Nov 2013 10:18 PM
It also works with variables

_G.Hi = "Stuff"

other script

print(_G.Hi)


In local scripts its good for saving information since its only that clients _G.

Like say the player picks a option in a gui or something, and so you make a _G. variable true (Like _G.Var = true or something)
Even if they die it has the variable
Report Abuse
ToxicDominator is not online. ToxicDominator
Joined: 24 Oct 2013
Total Posts: 8373
04 Nov 2013 10:21 PM
@scriptural

Better yet, combining both of our functions/variables:
_G.print(_G.Hi);
:P
Report Abuse
Scriptural is not online. Scriptural
Joined: 06 Sep 2013
Total Posts: 2979
04 Nov 2013 10:29 PM
we have the power
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
04 Nov 2013 11:31 PM
_G sucks
I prefer bindable functions, they are funner and less glitchy
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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