|
| 11 Aug 2012 02:55 PM |
| Is it possible to have all the code needed to fire a function on an event :connect all inside a part of _G |
|
|
| Report Abuse |
|
|
Dr01d3k4
|
  |
| Joined: 11 Oct 2007 |
| Total Posts: 17916 |
|
|
| 11 Aug 2012 02:57 PM |
_G["lavaTouched"] = function (p) if (not p.Parent:findFirstChild("Humanoid")) then return; end p.Parent.Humanoid.Health = 0; end end);
-- In a different script: script.Parent.Touched:connect(_G.lavaTouched); |
|
|
| Report Abuse |
|
|
juriaan
|
  |
| Joined: 25 Nov 2008 |
| Total Posts: 939 |
|
|
| 11 Aug 2012 02:57 PM |
Yes.
We can store it inside a Shared table and then dump the function and load it inside the game.
Example
function Hello() print("Hello world !") end
function Run(Function) loadstring(string.dump(Function))() end
Run(Hello)
|
|
|
| Report Abuse |
|
|
|
| 11 Aug 2012 02:58 PM |
SO there's no way to get
script.Parent.Touched:connect running INSIDE _G ? |
|
|
| Report Abuse |
|
|
Dr01d3k4
|
  |
| Joined: 11 Oct 2007 |
| Total Posts: 17916 |
|
| |
|
|
| 11 Aug 2012 03:00 PM |
In theory You could run an entire script inside _G including events etc. |
|
|
| Report Abuse |
|
|
Dr01d3k4
|
  |
| Joined: 11 Oct 2007 |
| Total Posts: 17916 |
|
|
| 11 Aug 2012 03:02 PM |
| Why would you want to...? If you mean just putting all the code to a game inside 1 script, then you don't need to use _G! |
|
|
| Report Abuse |
|
|
juriaan
|
  |
| Joined: 25 Nov 2008 |
| Total Posts: 939 |
|
|
| 11 Aug 2012 03:03 PM |
Nick
Why would you like to do that that kind of coding.
You can do this if you would like
Like I already said you can create a function that registers and then dump it.
Like put a Boolean inside the Workspace and then make a script like this
function _G.Toucher() Game:GetService("Workspace").Brick.Touch:connect(function(toucher) if Game:GetService("Players"):findFirstChild(toucher.Parent.Name) then print(toucher.Parent.Name) end end) end
Now we can do
_G.Toucher()
|
|
|
| Report Abuse |
|
|
|
| 11 Aug 2012 03:07 PM |
| Okay , Assuming I have a function in _G on that starts running from the time the server starts. Could it parse functions for events inside _G ? |
|
|
| Report Abuse |
|
|
juriaan
|
  |
| Joined: 25 Nov 2008 |
| Total Posts: 939 |
|
|
| 11 Aug 2012 03:09 PM |
Ofcourse you can Nick
function _G.Touch(Toucher) -- code blah blah end
Inside this script or a other script you just do a new event.
Game:GetService("Workspace").Part.Touched:connect(_G.Touch)
|
|
|
| Report Abuse |
|
|
|
| 11 Aug 2012 03:18 PM |
Okay, The aim is to get the game:GetService("Workspace").Part.Touched:connect inside _G and running. |
|
|
| Report Abuse |
|
|
oxcool1
|
  |
| Joined: 05 Nov 2009 |
| Total Posts: 15444 |
|
| |
|
|
| 11 Aug 2012 03:46 PM |
^ Like that.
Could _G.con = game.Workspace.Part.Touched:connect(func)
Then call another function in _G ? And would that _G.con work normally?
|
|
|
| Report Abuse |
|
|
ENET
|
  |
| Joined: 01 Jan 2010 |
| Total Posts: 4820 |
|
|
| 11 Aug 2012 03:49 PM |
_G is a table.... It is not a Context as you are thinking. IT is a table. You can't run a script in a table, you can only store variables(ints, strings, functions, other tables, environments) inside of _G... But _G is not a context.
You can however set _G as the environment as your script. Not sure why you would though.... |
|
|
| Report Abuse |
|
|
|
| 11 Aug 2012 03:58 PM |
@enet
" Not sure why you would though...."
I found that if I assign a variable such as _G.Var = 2 in a script inside studio. That value will remain in _G even if I use the reset (Re-wind button) button. Or delete the script. |
|
|
| Report Abuse |
|
|
ENET
|
  |
| Joined: 01 Jan 2010 |
| Total Posts: 4820 |
|
|
| 11 Aug 2012 04:06 PM |
@nick... that is not the same for events....
Now then when you save your place and exit studio and reopen it, your _G variables will be erased. They are only kept in the _G environment until you leave studio. So when you publish your game, they won't be included in the publishing. |
|
|
| Report Abuse |
|
|
ENET
|
  |
| Joined: 01 Jan 2010 |
| Total Posts: 4820 |
|
|
| 11 Aug 2012 04:08 PM |
In addition to ^^^
The only reason it stays in _G is because when you press the rewind button, the _G environment is not cleared. But if you exit studio or join a game it is reset. |
|
|
| Report Abuse |
|
|
|
| 11 Aug 2012 04:11 PM |
^^^ Dat feel when you just wasted about 1.5 hours on something redundant.
Thanks for filling me in. |
|
|
| Report Abuse |
|
|