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
 

Arguments Local?

Previous Thread :: Next Thread 
LunaScripter is not online. LunaScripter
Joined: 27 Nov 2008
Total Posts: 813
23 Aug 2014 03:04 PM
game.Players.PlayerAdded:connect(function(player)

end)

In that function, is the variable player local to it? So if one player joined, then another player joined while the first instance of the function was running, the player variable would not change in the first instance?
Report Abuse
LunaScripter is not online. LunaScripter
Joined: 27 Nov 2008
Total Posts: 813
23 Aug 2014 03:05 PM
Same question with non event based functions aswell
function test(a,b,c)

end

Are a b and c Local also?
Report Abuse
smiley599 is not online. smiley599
Joined: 23 Jan 2010
Total Posts: 21869
23 Aug 2014 03:05 PM
Yes it's local.
Report Abuse
smiley599 is not online. smiley599
Joined: 23 Jan 2010
Total Posts: 21869
23 Aug 2014 03:06 PM
Oh I'm not sure about the second one.

Give a full example.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
23 Aug 2014 03:44 PM
Yes all arguments are local.
Report Abuse
IthacaMedia is not online. IthacaMedia
Joined: 25 Jan 2014
Total Posts: 1337
23 Aug 2014 03:54 PM
Yes they're local by default. However, if you want to make them global, you can do the following:

_G.lastPlayerJoined = nil

game.Players.PlayerAdded:connect(function(player)
_G.lastPlayerJoined = player
end)
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
23 Aug 2014 03:56 PM
Why would you put them in the global table...

local x; -- Better to use a local variable in the outer-most scope, all scopes can access it and it's more efficient then a global (or shared, like what you did) variable.

game.Players.PlayerAdded:connect(function(player)
x = player;
end);
Report Abuse
IthacaMedia is not online. IthacaMedia
Joined: 25 Jan 2014
Total Posts: 1337
23 Aug 2014 04:13 PM
I did that for the full global effect, otherwise I agree that yours is better.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
23 Aug 2014 04:15 PM
Technically yours is incorrect in Rbx.Lua (but correct in regular Lua).
Roblox handles the _G table differently then it normally is.

In Roblox, _G is just a table shared between all scripts. Any new global variable won't be added to that table, unlike regular Lua. So what you are doing is actually adding a key-value pair into a shared table, instead of actually creating a global variable.
Report Abuse
IthacaMedia is not online. IthacaMedia
Joined: 25 Jan 2014
Total Posts: 1337
23 Aug 2014 04:26 PM
Yeah, that's what I meant by the full global effect, the ability to share variables between scripts.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
23 Aug 2014 04:31 PM
Oh, well yeah it's a bit misleading. The "full shared effect" might be a better name but thanks for clarifying.
Report Abuse
IthacaMedia is not online. IthacaMedia
Joined: 25 Jan 2014
Total Posts: 1337
23 Aug 2014 04:44 PM
Yeah lol :P.
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