Feche1320 Posted October 1, 2014 Share Posted October 1, 2014 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
Anubhav Posted October 1, 2014 Share Posted October 1, 2014 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 ) Link to comment
eAi Posted October 1, 2014 Share Posted October 1, 2014 See this post: viewtopic.php?f=148&t=77161 I'd say get/set element would be more optimal than the code provided. Link to comment
Moderators IIYAMA Posted October 1, 2014 Moderators Share Posted October 1, 2014 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
eAi Posted October 1, 2014 Share Posted October 1, 2014 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 IIYAMA Posted October 1, 2014 Moderators Share Posted October 1, 2014 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now