Jump to content

I need someone to Explain that


Hero192

Recommended Posts

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

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
  • Moderators

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

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...