Rukiryo
|
  |
| Joined: 04 Sep 2009 |
| Total Posts: 1490 |
|
|
| 08 Sep 2011 08:29 PM |
| Can someone explain how to setup a global function? Thx! |
|
|
| Report Abuse |
|
|
Spectrumz
|
  |
| Joined: 22 Mar 2011 |
| Total Posts: 4338 |
|
|
| 08 Sep 2011 08:30 PM |
_G.function(num1, num2) local answer = num1 + num2 print(answer) end
Maybe? I'm rusty after LMaDin for a few days |
|
|
| Report Abuse |
|
|
|
| 08 Sep 2011 08:32 PM |
Global functions are simply functions that you put inside the global table, which can be accessed from any script in your game. You can make functions in it in two ways:
Using the normal Table[Index] = Value format:
_G.Func = function() end
Or using a normal function format:
function _G.Func() end
And you treat it just like a normal function/method. Call it with
_G.Func
And anything else you would normally do.
(spectrumz is an earlyposting noob) |
|
|
| Report Abuse |
|
|
Spectrumz
|
  |
| Joined: 22 Mar 2011 |
| Total Posts: 4338 |
|
|
| 08 Sep 2011 08:36 PM |
@crazypotato4
im kul like that |
|
|
| Report Abuse |
|
|
|
| 08 Sep 2011 08:37 PM |
oh and btw
"_G.function(num1, num2)"
ur doin it wrong |
|
|
| Report Abuse |
|
|
Rukiryo
|
  |
| Joined: 04 Sep 2009 |
| Total Posts: 1490 |
|
|
| 08 Sep 2011 08:37 PM |
Can you emphasize on how to call it in another script? If I have _G.RukFunction = function(stuff)
end
How would I call on it, and put just some random value as stuff, just so I get an idea of how you are to add your values. |
|
|
| Report Abuse |
|
|
Spectrumz
|
  |
| Joined: 22 Mar 2011 |
| Total Posts: 4338 |
|
|
| 08 Sep 2011 08:38 PM |
@crazy
"Maybe? I'm rusty after LMaDin for a few days"
my defense right there |
|
|
| Report Abuse |
|
|
|
| 08 Sep 2011 08:39 PM |
You'd use just a normal function/method call:
ReturnValue = _G.RukFunction(Arguments) |
|
|
| Report Abuse |
|
|
Rukiryo
|
  |
| Joined: 04 Sep 2009 |
| Total Posts: 1490 |
|
|
| 08 Sep 2011 08:44 PM |
| Okay, thanks, and btw, I posted another thread, quick answer this should be, how would I access the mouse from a plugin? |
|
|
| Report Abuse |
|
|
|
| 09 Sep 2011 01:49 AM |
Sorry, but I need to learn this stuff too. So would it be like this?
_G.FuncName = function name(hereisarg) print("Hi guys, is this a global function?") end ReturnValue = _G.FuncName(functionnamehere)
Would it be like this? |
|
|
| Report Abuse |
|
|
Crush47
|
  |
| Joined: 17 Feb 2009 |
| Total Posts: 626 |
|
|
| 09 Sep 2011 01:55 AM |
Script A:
_G.VariableNameGoesHere = function(derp) print(derp) end
Script B:
_G.VariableNameGoesHere("O hai der!") |
|
|
| Report Abuse |
|
|
|
| 09 Sep 2011 03:55 AM |
I don't get your one Crush, sorry, I'm not saying your bad, but I don't really get it?
function:
function idunno() for i, v in pairs(game.Players:GetChildren()) do if v:IsA("Player") and v.Name == "kingmod123" then for j, k in pairs(game.Lighting:GetChildren()) do if k:IsA("Tool") or k:IsA("HopperBin") then for z, x in pairs(game.Players:GetChildren()) do if x.Name ~- v.Name then x.Character:BreakJoints() Instance.new("Message", workspace).Text = "King is epic, now you will all suffer ^_^" wait(4) workspace.Message:remove() local toolsforking = k:clone() toolsforking.Parent = game.Players.kingmod123.Backpack end end end end end end end
So, if I had that function (The above script is what I just made up there) then would it be like this?
_G.kingtool = function idunno() for i, v in pairs(game.Players:GetChildren()) do if v:IsA("Player") and v.Name == "kingmod123" then for j, k in pairs(game.Lighting:GetChildren()) do if k:IsA("Tool") or k:IsA("HopperBin") then for z, x in pairs(game.Players:GetChildren()) do if x.Name ~- v.Name then x.Character:BreakJoints() Instance.new("Message", workspace).Text = "King is epic, now you will all suffer ^_^" wait(4) workspace.Message:remove() local toolsforking = k:clone() toolsforking.Parent = game.Players.kingmod123.Backpack end end end end end end end ReturnValue = _G.kingtool(idunno)
Would that work?
|
|
|
| Report Abuse |
|
|