Sisqo0 Posted August 8, 2020 Share Posted August 8, 2020 First :- I wanna know, what is the best way to save table in element data ? i know 2 ways only but if there are more and better than those, i hope you tell me --1st way >> table {} setElementData(player,"data",{x,y,z}) --2nd way >> toJSON setElementData(player,"data",toJSON(x,y,z)) Second :- What's the best way to extract variables from table. I know 3 ways but i don't know which one is the best --1st way >> unpack() setElementData(player,"data",{x,y,z}) local data = getElementData(player,"data") local x,y,z = unpack(data) --2nd way >> data[i] setElementData(player,"data",{x,y,z}) local data = getElementData(player,"data") local x,y,z = data[1],data[2],data[3] --3rd way >> fromJSON setElementData(player,"data",toJSON(x,y,z)) local data = fromJSON(getElementData(player,"data")) --then i use the 3rd line of either of the last 2 ways Thanks in advance Link to comment
Sisqo0 Posted August 8, 2020 Author Share Posted August 8, 2020 Third :- if there is a function which was attached to event and you call it a lot in the same and other side (client or server) ,would it be better if we just call the function in the same side by its name or using this :- triggerEvent("function-name") Link to comment
Moderators Patrick Posted August 8, 2020 Moderators Share Posted August 8, 2020 The sort answer: --1st way >> table {} setElementData(player,"data",{x,y,z}) and --2nd way >> data[i] setElementData(player,"data",{x,y,z}) local data = getElementData(player,"data") local x,y,z = data[1],data[2],data[3] You can test all of them easily for yourself: -- CLIENT local startTick = getTickCount() for i = 1, 100000 do -- execute the code 100000 times setElementData(localPlayer,"data",{0,0,0}) local data = getElementData(localPlayer,"data") local x,y,z = data[1],data[2],data[3] end local endTick = getTickCount() print("Execution time:", endTick - startTick .. " ms") And you should check this: 1 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