|
| 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 |
|
|
|
| 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
|
  |
| Joined: 23 Jan 2010 |
| Total Posts: 21869 |
|
| |
|
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
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 23 Aug 2014 03:44 PM |
| Yes all arguments are local. |
|
|
| Report Abuse |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 23 Aug 2014 04:13 PM |
| I did that for the full global effect, otherwise I agree that yours is better. |
|
|
| Report Abuse |
|
|
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 |
|
|
|
| 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
|
  |
| 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 |
|
|
| |
|