Jump to content

Whats the most efficient?


aintaro

Recommended Posts

Posted

Hello,

What is the most efficient code :

EXAMPLE 1

triggerClientEvent("eventName", getResourceRootElement(getThisResource()), afunction) 

triggerClientEvent("eventName", getRootElement(), afunction) 

thanks in advance,

Greetz, Aintaro!

Posted

That only changes the source of event that is triggered, so in first case it would be resource's root element, while in the other it would be regular root element (containing all other elements). I don't think this affects the efficiency at all, unless you are trying to parse some element as source, then it depends on what do you put as source.

Posted
That only changes the source of event that is triggered, so in first case it would be resource's root element, while in the other it would be regular root element (containing all other elements). I don't think this affects the efficiency at all, unless you are trying to parse some element as source, then it depends on what do you put as source.

Root executes faster than getrootelement () so thats why I was wondering if it could make a difference

Posted

Im not sure about it but i read somewhere on wiki that having lots of event handlers handled to root usea more cpu.

Dont forget that there are predefined variables root and resourceRoot.

Posted

Tre.png

I think that the higher up in element tree the element you are attaching with is, the slower it will take to trigger the event, but only if you are triggering with a child of the attached element. Like if you attach event to root, but trigger the event with a player as source element.

Depending on how mta devs have implemented it, it may also take longer to trigger if you have many events that are attached to the same element than attaching to an element that doesn't have many events attached to it.

But anways, resourceRoot should be more efficient than root. Though the difference in performance may be non-existent.

Posted
Note: To save client CPU, you should avoid setting sourceElement to the root element where possible. Using resourceRoot is usually sufficient if the event is handled by the same resource on the client.

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