Sign in to follow this  
Feche1320

Question regarding script optimization and safety

Recommended Posts

Hello, I want to use setElementData and getElementData with a global element, for example getting the element data client side and server side.. so my question is, is it safe to use root element like this?

setElementData(root, "whateverhere", true) 
getElementData(root, "whateverhere") 

Or is it just a waste of CPU and RAM resources? I could use it with something smaller like an object as element? the only problem using a object is that it won't be server/client side usable.. thanks.

Share this post


Link to post

Don't use elementData for such a thing.

  
-- SERVER 
myData = {} -- creating a table 
  
function setMyData(player, value) 
     myData[player] = value -- setting the player value in table 
     return true -- returning that it was sucessfully done 
end 
  
function getMyData(player) 
     return myData[player] or false -- returning the data player has 
end 
  
function sendMyDataToClient() 
     for k,v in ipairs(getElementsByType("player")) do -- looping through all players 
           triggerClientEvent(v, "sendMyData", v, getMyData(v)) -- triggering a event to client "sendMyData", with the arguments of getMyData(v) which means which data player has! 
     end 
end 
  
  

  
-- CLIENT 
addEvent("sendMyData", true) 
addEventHandler("sendMyData", root, 
    function(data) 
         outputChatBox(data) -- output the player its data 
    end 
) 
  
  

Share this post


Link to post

The only thing you have to know, is that everything which isn't using the lua memory is SLOWER.

(elementdata slow, accountdata/databases very slow and xml very very slow)

You may can say they are fast enough, but lua memory is more or less optimised memory for quick use.

Lua memory > variables. (which can hold: strings, numbers, tables, nil's, functions, boolean's etc....)

Share this post


Link to post

Sure, that's true if you only want to send your data to a single player, but if you want every player to get that data, then I'm fairly sure that setElementData is the most optimal way, or at worst, it makes very little difference.

Share this post


Link to post

Elementdata uses in my experience circa 5x less data transfer.

So yes it is far more optimal way for sharing it with all the clients, which is a big difference.

It only isn't isn't manage able per client and it has very less options.

It is just what you want to accomplish.

Share this post


Link to post

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.