chaokid9
|
  |
| Joined: 29 Aug 2008 |
| Total Posts: 6187 |
|
|
| 12 Apr 2012 09:03 AM |
When I make a script I always would do something like this:
function newPlayer(player)
[code]
game.Players.PlayerAdded:connect(newPlayer)
But I have seen people make codes where the first and last line are like, combined? Example I saw on a thread earlier:
game.Players.PlayerAdded:connect(function(p) p.CharacterAdded:connect(function(character) end) end)
Somehow that is a complete script, but I don't see a function and connection line. It is like they are combined. Is there any difference? I think my way is simpler and easier to remember. |
|
|
| Report Abuse |
|
|
su8
|
  |
| Joined: 06 Mar 2009 |
| Total Posts: 6334 |
|
|
| 12 Apr 2012 09:12 AM |
>but I don't see a function and connection line
You must be blind game.Players.PlayerAdded:connect(--connection line function(p)--function
It's same as
p = function(blah) print(blah.Name) end game.Players.PlayerAdded:connect(p)
But without a variable; game.Players.PlayerAdded:connect(function(blah) print(blah.Name) end)
|
|
|
| Report Abuse |
|
|
Quovis
|
  |
| Joined: 24 Mar 2012 |
| Total Posts: 494 |
|
|
| 12 Apr 2012 09:53 AM |
| It's called anonymous functions. |
|
|
| Report Abuse |
|
|
|
| 12 Apr 2012 10:01 AM |
function newPlayer(player) --code end
game.Players.PlayerAdded:connect(newPlayer)
What this does is cconnects the event called PlayerAdded when a player is added to game.Players to the function called newPlayer, because you created a function outside of the direct event.
game.Players.PlayerAdded:connect(function(player) --code end)
What this does is connects the event called PlayerAdded when a player is added to game.Players to the function within the event call so you wont need to call an outside function as you have made a function within the parameters of the connect method.
The connect method redirects an event to a function, weather the function is set as a variable or the functino is created directly within the parameters of the method itself. I hope this answers your question in more detail. |
|
|
| Report Abuse |
|
|