Jump to content

just wanted to ask something about addEventHandler

Recommended Posts

i just want to ask is there any difference between this:

--other part of code 
end) -- ) closing the up addEventHandler 



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

You may view them in a line to see the difference better:

addEventHandler("onPlayerJoin",root,function() end) 

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...