Jump to content

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.

Link to comment

Don't use elementData for such a thing.

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 
function getMyData(player) 
     return myData[player] or false -- returning the data player has 
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! 

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

Link to comment
  • Moderators

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

Link to comment

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.

Link to comment
  • Moderators

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.

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