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
 

I'm confused about functions?

Previous Thread :: Next Thread 
chaokid9 is not online. 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 is not online. 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 is not online. Quovis
Joined: 24 Mar 2012
Total Posts: 494
12 Apr 2012 09:53 AM
It's called anonymous functions.
Report Abuse
Robertoman is not online. Robertoman
Joined: 10 May 2007
Total Posts: 6369
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
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