Jump to content

getElementData and onClientRender


Feche1320

Recommended Posts

if you'd have some experience you'd know how to decrease that flaw to minimum.

And you obviously know how to, don't you?

Anyway, I disagree that using element data is bad. So long as you use it properly, the performance impact won't be too significant.

What I disagree with however, is to use it with onClientRender. What people always seem to fail to realize, despite me editing the MTA Wiki - any code you use with onClientRender will be run with each frame.

And generally, a game renders 30 to 60 frames per second, depending on your settings. I don't know why you'd have to set someone's data 30-60 times per second...?

Link to comment
  • Moderators

The important thing is that you check if the elementdata has changed.

Elementdata has it's own update rate(so NO not every frame), but it will also update when you set the elementdata to the same value.

"Why does it updates(synchronisation) when the value is the same?"

Because serverside/clientside can use the elementdata without synchronisation, so it has to be updated on the other side too.

Can simply be reduced with:

if getElementData(element,"key") ~= newData then 
setElementData(element,"key",newData) 
end 

The update rate of elementdata is very quick, so getTickCount() can reduce the amount of updates.

local nextUpdate = 0 
  
addEventHandler("onClientRender",root, 
function () 
local timeNow = getTickCount() 
if timeNow > nextUpdate then 
nextUpdate = timeNow+1000 
outputChatBox("update!!!!!") 
end 
end) 

Elementdata can be handy but you have to be careful how many times you execute it (on both sides).

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