koragg Posted December 15, 2017 Share Posted December 15, 2017 (edited) I just wish that this would get clear to me once and for all I have a lot of times something like setElementData(localPlayer, "data", false) whenever I don't need the particular element data anymore. Now my question (for months) has been - is it better to use setElementData(localPlayer, "data", nil) instead? I'm talking performance wise here. I've used elementData A LOT so maybe it can cause some lags if not used properly, idk. Edited December 15, 2017 by koragg Link to comment
MisterQuestions Posted December 15, 2017 Share Posted December 15, 2017 On server side you can call removeElementData, how ever having lot of element data isnt performance helful. Link to comment
Moderators IIYAMA Posted December 15, 2017 Moderators Share Posted December 15, 2017 (edited) This is not a lua question, but more like a MTA question. Because MTA responsible for sending the data. If you want to know which one uses less data, then this is one of the ways to do this: (I am not sure if lua in elementdata is used differently in the network in compare to trigger events, but I don't think so.) Client local prepareLargePacket1 = {} local prepareLargePacket2 = {} for i=1, 1000 do prepareLargePacket1[i] = false prepareLargePacket2[i] = nil end triggerLatentServerEvent ("test1", resourceRoot, unpack(prepareLargePacket1)) local eventHandles = getLatentEventHandles() local eventHandle1 = eventHandles[#eventHandles] local status1 = getLatentEventStatus(eventHandle1) if status1 then iprint("status1 totalSize:", status1.totalSize) end --------------------------------------------------------- --------------------------------------------------------- triggerLatentServerEvent ("test2", resourceRoot, unpack(prepareLargePacket2)) local eventHandles = getLatentEventHandles() local eventHandle2 = eventHandles[#eventHandles] local status2 = getLatentEventStatus(eventHandle2) if status2 then iprint("status2. totalSize:", status2.totalSize) end Server addEvent("test1", true) addEvent("test2", true) Let me know what the answer is! Edited December 15, 2017 by IIYAMA Link to comment
koragg Posted December 15, 2017 Author Share Posted December 15, 2017 (edited) @IIYAMA status1 = 641 & status2 = 14 when I start your test script. If that means what I think it means then I better start replacing all 'false' to 'nil' when removing elementData 1 hour ago, MisterQuestions said: On server side you can call removeElementData, how ever having lot of element data isnt performance helful. Yes, but on client-side I can only make it 'nil'. And by 'performance wise' I meant which is better for less system strain, 'false' or 'nil' Edited December 15, 2017 by koragg Link to comment
Moderators IIYAMA Posted December 15, 2017 Moderators Share Posted December 15, 2017 (edited) hmm, interesting. That is a very big difference. And what happens if you change this: local prepareLargePacket1 = {} local prepareLargePacket2 = {} for i=1, 1000 do prepareLargePacket1[i] = false prepareLargePacket2[i] = nil end -- NEW -- prepareLargePacket1[#prepareLargePacket1 + 1] = 1 prepareLargePacket2[#prepareLargePacket2 + 1] = 1 --------- It should check if the there are any nil parameters removed before sending. Edited December 15, 2017 by IIYAMA Link to comment
koragg Posted December 15, 2017 Author Share Posted December 15, 2017 8 minutes ago, IIYAMA said: hmm, interesting. That is a very big difference. And what happens if you change this: local prepareLargePacket1 = {} local prepareLargePacket2 = {} for i=1, 1000 do prepareLargePacket1[i] = false prepareLargePacket2[i] = nil end -- NEW -- prepareLargePacket1[#prepareLargePacket1 + 1] = 1 prepareLargePacket2[#prepareLargePacket2 + 1] = 1 --------- It should check if the there are any nil parameters removed before sending. 1641 on both. 1 Link to comment
Moderators IIYAMA Posted December 15, 2017 Moderators Share Posted December 15, 2017 Then there is no difference I think. 1 Link to comment
koragg Posted December 15, 2017 Author Share Posted December 15, 2017 (edited) 1 hour ago, IIYAMA said: Then there is no difference I think. Hm ok then. Btw, does 'removeElementData(source, "data")" do the same thing as 'setElementData(source, "data", nil)' ? Edited December 15, 2017 by koragg Sry for no indent but I'm on phone now. Link to comment
Moderators IIYAMA Posted December 15, 2017 Moderators Share Posted December 15, 2017 It should do the same thing, even though removeElementData would do a quicker job. At least forcing it to be removed. 1 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