Global Functions: Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>Dingdong272
ROBLOX How To's Decompiled to seperate pages.
>Dingdong272
m pre tags
Line 3: Line 3:
If you know how to use the _G[] (global) command, this might come more easily to you than others. This is basically how a global command works:
If you know how to use the _G[] (global) command, this might come more easily to you than others. This is basically how a global command works:


_G["Bob"] = game.Workspace.Bob
<pre>_G["Bob"] = game.Workspace.Bob</pre>


If you're in a ScriptBuilder, you can exit that script and open a new one. Put this in it:
If you're in a ScriptBuilder, you can exit that script and open a new one. Put this in it:


Bob.Torso:Remove()
<pre>Bob.Torso:Remove()</pre>


run that script, and your torso gets removed! Why? Because the _G[] (global) command makes "Bob" availible in every script. Now, to get a global function:
run that script, and your torso gets removed! Why? Because the _G[] (global) command makes "Bob" availible in every script. Now, to get a global function:


_G["Lazer"] = function(person) person.Torso:Remove() end
<pre>_G["Lazer"] = function(person) person.Torso:Remove() end</pre>


Now exit that, and do this:
Now exit that, and do this:


Lazer(game.Workspace.Bob)
<pre>Lazer(game.Workspace.Bob)</pre>


If your character's name is, "Bob," you should have your torso removed.
If your character's name is, "Bob," you should have your torso removed.

Revision as of 15:21, 6 June 2008

Have you ever wondered how things like :Remove() and :Clone() always work, even though you've never indexed it? Here's how:

If you know how to use the _G[] (global) command, this might come more easily to you than others. This is basically how a global command works:

_G["Bob"] = game.Workspace.Bob

If you're in a ScriptBuilder, you can exit that script and open a new one. Put this in it:

Bob.Torso:Remove()

run that script, and your torso gets removed! Why? Because the _G[] (global) command makes "Bob" availible in every script. Now, to get a global function:

_G["Lazer"] = function(person) person.Torso:Remove() end

Now exit that, and do this:

Lazer(game.Workspace.Bob)

If your character's name is, "Bob," you should have your torso removed.