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
 

Re: I pretty much only use anonymous functions.

Previous Thread :: Next Thread 
EcIiptic is not online. EcIiptic
Joined: 12 Aug 2009
Total Posts: 13737
11 Feb 2014 05:11 PM
game.Players.PlayerAdded:connect(function(player)
end)

function AddPlayer(player)
end
game.Players.PlayerAdded:connect(AddPlayer)


So much easier to write that :)

And this way, you don't forget to connect your functions :P
Report Abuse
Swordphin123 is not online. Swordphin123
Joined: 09 Apr 2008
Total Posts: 5234
11 Feb 2014 05:15 PM
I agree, however functions are their own separate thing as well. Anonymous functions are usually used on one-time things while functions in general can be used multiple times over. I guess it depends on the efficiency of your code whenever to choose between the two.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
11 Feb 2014 07:04 PM
Anonymous functions are less efficient, but if you plan on running something for a limited amount of times, it's better so you don't have to clutter up the environment with 1 extra function, which is very little.
Report Abuse
adark is not online. adark
Joined: 13 Jan 2008
Total Posts: 6412
11 Feb 2014 07:38 PM
I have absolutely no idea how you think anonymous functions are less efficient than named functions. If anything, they're more efficient since the environment, as you said, isn't cluttered with an extra entry.

Please explain your reasoning. :o
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
11 Feb 2014 07:45 PM
I ran tests a couple years ago (using functions and anonymous functions) and I found out that after calling the function an X amount of times (I do not remember) its overall speed was more that of creating the same function that amount of times.

As in, creating functions are slower than calling them over a bunch of times. Although my test may have been inaccurate due to using different versions of Lua and possibly just computer lag
Report Abuse
adark is not online. adark
Joined: 13 Jan 2008
Total Posts: 6412
11 Feb 2014 07:54 PM
Oooh, I see now.

Thanks for pointing that out.
If you can, run those tests again. It was my belief that the function gets cached, but that may not be the case.

Either way, though, the difference in speed is barely noticeable in most cases.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
11 Feb 2014 08:03 PM
Alright, hold up
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
11 Feb 2014 08:16 PM
I got these results (same tests, done a lot of times, taken the average)

Normal Average 0.0019834196251568
Anonymous Average 0.0022870009163925
Report Abuse
adark is not online. adark
Joined: 13 Jan 2008
Total Posts: 6412
11 Feb 2014 08:17 PM
Huh.

Well, the more you know.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
11 Feb 2014 08:20 PM
As in, the difference (did with like, thousands of calls and thousands of creations) is so small, or maybe none at all, that it's not even worth mentioning
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
11 Feb 2014 08:21 PM
Oh, but this could have been ruined by float precision.
Report Abuse
maxomega3 is not online. maxomega3
Joined: 11 Jun 2010
Total Posts: 10668
11 Feb 2014 08:22 PM
Microseconds of difference, it might save your life. You never know!
Report Abuse
jmasterj10 is not online. jmasterj10
Joined: 19 Sep 2010
Total Posts: 735
12 Feb 2014 03:19 AM
I like them because when I do Touched functins I always forget to call it when I dont use those functions
Report Abuse
EcIiptic is not online. EcIiptic
Joined: 12 Aug 2009
Total Posts: 13737
12 Feb 2014 09:21 AM
btw I forgot to add.

I use normal functions all the time when I need to do something over and over again.

But when doing something like an event that fires when a brick is touched, or a GUI is clicked. I tend to stick to the anonymous functions.
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