Hero192 Posted February 1, 2016 Share Posted February 1, 2016 Hello dear scripters, Today I want to know when should we use root or getRootElement() and when should we use source in trigger(Server/Client) Event and in addEventHandler For example, I see in codes sometime: they use root and sometime they use source or localPlayer addEventHandler ( "onClientPlayerChangeNick", getRootElement(),funcName)--This with root element why? addEventHandler ( "onClientPlayerChangeNick", getLocalPlayer(),funcName)--and this with localPlayer Thanks in advance. Link to comment
Bonsai Posted February 1, 2016 Share Posted February 1, 2016 getRootElement() or root will trigger that event, and therefore call the function when any player changes his nick, as all players are childs of the root element. (Check the Element Tree in wiki) If you set the localPlayer as source, it will only trigger if the localPlayer changes his nick. You only have to be careful and checking the wiki what the source of an event will be. (players, vehicles, markers..) Usually its best not to set root, especially when working with ResourceStart events. Bonsai Link to comment
Hero192 Posted February 1, 2016 Author Share Posted February 1, 2016 Thanks alot I apreciate that, One more thing, I want to know when should I use Break and While I read that in lua website but I didn't understand it well Link to comment
Moderators IIYAMA Posted February 1, 2016 Moderators Share Posted February 1, 2016 while is a kind of statement for a while loop. A loop is for executing the same code multiple times. and a break is for stopping an active loop. But you should not worry so much about those two. The while loop isn't required often, just once in a while under some circumstances. 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