Jump to content

[HELP or ADVICE] elementData...again


koragg

Recommended Posts

I just wish that this would get clear to me once and for all :D

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 by koragg
Link to comment
  • Moderators

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 by IIYAMA
Link to comment

@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 :D

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 by koragg
Link to comment
  • Moderators

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 by IIYAMA
Link to comment
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.

  • Like 1
Link to comment
1 hour ago, IIYAMA said:

Then there is no difference I think. O.o

 

Hm ok then. Btw, does 'removeElementData(source, "data")" do the same thing as 'setElementData(source, "data", nil)' ?

Edited by koragg
Sry for no indent but I'm on phone now.
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...