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: Globa Functions?

Previous Thread :: Next Thread 
Rukiryo is not online. 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 is not online. 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
crazypotato4 is not online. crazypotato4
Joined: 22 Feb 2010
Total Posts: 20000
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 is not online. Spectrumz
Joined: 22 Mar 2011
Total Posts: 4338
08 Sep 2011 08:36 PM
@crazypotato4

im kul like that
Report Abuse
crazypotato4 is not online. crazypotato4
Joined: 22 Feb 2010
Total Posts: 20000
08 Sep 2011 08:37 PM
oh and btw

"_G.function(num1, num2)"

ur doin it wrong
Report Abuse
Rukiryo is not online. 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 is not online. 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
crazypotato4 is not online. crazypotato4
Joined: 22 Feb 2010
Total Posts: 20000
08 Sep 2011 08:39 PM
You'd use just a normal function/method call:

ReturnValue = _G.RukFunction(Arguments)
Report Abuse
Rukiryo is not online. 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
kingmod123 is not online. kingmod123
Joined: 16 May 2009
Total Posts: 699
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 is not online. 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
kingmod123 is not online. kingmod123
Joined: 16 May 2009
Total Posts: 699
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
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