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 |
|
|
|
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
| |
|
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
|
  |
| Joined: 13 Jan 2008 |
| Total Posts: 6412 |
|
|
| 11 Feb 2014 08:17 PM |
Huh.
Well, the more you know. |
|
|
| Report Abuse |
|
|
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
|
  |
| 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
|
  |
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|