Jump to content

getElementData and onClientRender


Feche1320

Recommended Posts

Posted

Hey guys, another of my big questions :o

If I use getElementData in onClientRender, the client will call the server each time the frame is rendered or setElementData sends the data to the client when it is updated and it stores it clienside?

Posted

Theorically as manawydan data is synchronized, this means the client will not call the server each time it wants to check the data, it will ask for the currently local-stored one wich can be itself modified by the server.

My ingame nick is ~HyPeX~

BF3 Gamemode Progress: ~30% - Currently working on AI & MapManager

gKhdyRJ.png

Posted

It can cause massive lag!

No

viewtopic.php?f=148&t=77161

Stop thinking it won't, it will decrease performence.

You don't care right? See performence browser.

Posted

It can cause massive lag!

No

viewtopic.php?f=148&t=77161

Stop thinking it won't, it will decrease performence.

You don't care right? See performence browser.

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

If you find my post useful or if it helped you, please like my post :)
Ingame name: ZoeN

560x95_FFFFFF_FF9900_000000_000000.png

Posted

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

If I help you in a thread and you need further assistance, please don't PM me - use the thread you created instead. This way everyone on the forum can take advantage of it.

  • Moderators
Posted

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

  • Thanks 1

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

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