|
| 11 Sep 2016 09:56 AM |
Long story short: I'm new and have been using the knowledge I have to make scripts. I have a question though about functions. What's the difference between:
function Name() end
part.Touched:connect(Name)
and this:
part.Touched:connect (function
end)
All help is appreciated.
|
|
|
| Report Abuse |
|
|
yankana
|
  |
| Joined: 17 Jun 2011 |
| Total Posts: 431 |
|
|
| 11 Sep 2016 10:16 AM |
| Creating the function allows for multiple uses instead of having to write it down twice or more times. Functions without names are called Anonymous functions that are made directly, e.g. the second function in your post. |
|
|
| Report Abuse |
|
|
|
| 11 Sep 2016 10:17 AM |
Thanks. Also, is it possible for me to have more than one anonymous function on one script?
|
|
|
| Report Abuse |
|
|
yankana
|
  |
| Joined: 17 Jun 2011 |
| Total Posts: 431 |
|
|
| 11 Sep 2016 10:19 AM |
| Yes, functions don't have limited amount of uses. |
|
|
| Report Abuse |
|
|
|
| 11 Sep 2016 10:19 AM |
Thanks again! It means alot to me.
|
|
|
| Report Abuse |
|
|
Skellobit
|
  |
| Joined: 13 Apr 2016 |
| Total Posts: 12758 |
|
|
| 11 Sep 2016 10:20 AM |
The top one is an example of naming a function then connecting an event to it while the bottom is called an anonymous function because it doesn't have a name
Formerly ToxicDominator - add 17,509 posts |
|
|
| Report Abuse |
|
|
| |
|
Skellobit
|
  |
| Joined: 13 Apr 2016 |
| Total Posts: 12758 |
|
|
| 11 Sep 2016 10:24 AM |
Also, for most cases you might want to put "local" in front of your global variables since local variables are quicker to access; it would look like this:
local function Name() end
and same with other variables
Formerly ToxicDominator - add 17,509 posts |
|
|
| Report Abuse |
|
|
| |
|