toxicsmoke11 Posted April 15, 2014 Share Posted April 15, 2014 i just want to ask is there any difference between this: addEventHandler("onPlayerJoin",root --other part of code end) -- ) closing the up addEventHandler and addEventHandler("onPlayerJoin",root,functionName) only thing i've noticed is that up example is used when theres no function name,but i am curious is there any difference other than that? Link to comment
Saml1er Posted April 15, 2014 Share Posted April 15, 2014 addEventHandler("onPlayerJoin",root function () end -- This end is for the function ) And there is no other difference. Link to comment
Karuzo Posted April 15, 2014 Share Posted April 15, 2014 You use addEventHandler("onPlayerJoin",root, function() end ) for functions which you don't call anymore in your script , i call those functions just anonymouse functions. Link to comment
toxicsmoke11 Posted April 15, 2014 Author Share Posted April 15, 2014 okay thanks for explaining Saml1er and KRZO Link to comment
Vinctus Posted April 15, 2014 Share Posted April 15, 2014 I usually use the first example with commandhandlers and onResourceStart functions Link to comment
Mr_Moose Posted April 15, 2014 Share Posted April 15, 2014 You may view them in a line to see the difference better: addEventHandler("onPlayerJoin",root,function() end) addEventHandler("onPlayerJoin",root,functionName) So what we can see here is that the first one has the actual function inside the handler as a parameter, this is useful when you want to call a function inside another function and thereby access local variables from the first function inside the second function. setTimer() has some good samples of this. Anyway by using local variables you save memory so it's pretty good for the performance if you want to optimize your scripts. The second one adds a command handler for an already existing function within the same source file, just remember that the function need to be defined before this is executed so it should be added below the function it trigger or inside another function basically. This is more useful for large functions which contains a lot of code but both works no matter what actually. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now