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 |
|
|
|
| 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 |
|
|
| |
|
|
| 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
|
  |
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 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 |
|
|
|
| 04 Nov 2013 10:21 PM |
@scriptural
Better yet, combining both of our functions/variables: _G.print(_G.Hi); :P |
|
|
| Report Abuse |
|
|
| |
|
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 |
|
|