'LinKin Posted October 8, 2014 Share Posted October 8, 2014 Hello, I was making a deadlist script, and I made a function to set the text of each entry accordingly to the deadlist mode (which can be changed by the client) On first instance I had Solution #1 (Which total's size is 1874 bytes) which was a flat function but with a lot of redundant code, it worked perfectly. No problems at all. Then, I optimizated the code and made Solution #2. It managed to reduce its size to 761 bytes. But when I went to test it, it was slower. The rendering was slower and the animation that I make for the deadlist wasn't good at all, it was mostly absent (it couldn't be really seen by the client (me)), but I'm still wondering why? It's the same thing but made in a better way, and how come the Solution #1 is faster than Solution #2? Here's the code of both solutions: (It's just part of the script) Solution #1 function setTextAccordingToMode(listRow) if deadListMode == 1 then -- Full if listRow then local dxText = listRow.dxText dxText:text(listRow.pos..listRow.highLight..listRow.deadName..listRow.killName) dxText:visible(true) return end for _, aRow in ipairs(deadList) do local dxText = aRow.dxText dxText:text(aRow.pos..aRow.highLight..aRow.deadName..aRow.killName) dxText:visible(true) end elseif deadListMode == 2 then -- No Killers if listRow then local dxText = listRow.dxText dxText:text(listRow.pos..listRow.highLight..listRow.deadName) dxText:visible(true) return end for _, aRow in ipairs(deadList) do local dxText = aRow.dxText dxText:text(aRow.pos..aRow.highLight..aRow.deadName) end elseif deadListMode == 3 then -- No Spectators & No Killers if listRow then local dxText = listRow.dxText dxText:text(listRow.pos..colors["C_TARG"]..listRow.deadName) dxText:visible(true) return end for _, aRow in ipairs(deadList) do local dxText = aRow.dxText dxText:text(aRow.pos..colors["C_TARG"]..aRow.deadName) end elseif deadListMode == 4 then -- No Spectators if listRow then local dxText = listRow.dxText dxText:text(listRow.pos..colors["C_TARG"]..listRow.deadName..listRow.killName) dxText:visible(true) return end for _, aRow in ipairs(deadList) do local dxText = aRow.dxText dxText:text(aRow.pos..colors["C_TARG"]..aRow.deadName..aRow.killName) end elseif deadListMode == 5 then -- Hide List if listRow then local dxText = listRow.dxText dxText:text(listRow.pos..listRow.highLight..listRow.deadName..listRow.killName) return end for _, aRow in ipairs(deadList) do local dxText = aRow.dxText dxText:visible(false) end end end Solution #2 function setTextAccordingToMode(listRow) if listRow then local dxDraw = listRow.dxText dxDraw:text(getTextByMode(listRow)) if deadListMode ~= 5 then dxDraw:visible(true) end return end for _, aRow in ipairs(deadList) do local dxDraw = aRow.dxText dxDraw:text(getTextByMode(aRow)) end end function getTextByMode(aRow) if not aRow then return end local theText = "" if deadListMode == 1 or deadListMode == 5 then theText = aRow.pos..aRow.highLight..aRow.deadName..aRow.killName return theText elseif deadListMode == 2 then theText = aRow.pos..aRow.highLight..aRow.deadName return theText elseif deadListMode == 3 then theText = aRow.pos..colors["C_TARG"]..aRow.deadName return theText elseif deadListMode == 4 then theText = aRow.pos..colors["C_TARG"]..aRow.deadName..aRow.killName return theText end end PS: The size I'm talking about is the size of the function only, not the whole script. And once again; Does the client's computer capacity affect the performance of clientside scripts? I'd say yes of course it does, but I'm just making sure I'm right Link to comment
Anubhav Posted October 8, 2014 Share Posted October 8, 2014 I don't think size affects this. Size only affects the download, how the script is written affects the performence! Link to comment
GhostXoP Posted October 8, 2014 Share Posted October 8, 2014 I don't think size affects this. Size only affects the download, how the script is written affects the performence! ...That isn't the question here. Quit wasting space on the forums. Link to comment
Anubhav Posted October 8, 2014 Share Posted October 8, 2014 PS: The size I'm talking about is the size of the function only, not the whole script. And once again; Does the client's computer capacity affect the performance of clientside scripts? I'd say yes of course it does, but I'm just making sure I'm right Shutup, read the post carefully, he wants to be sure if he's right! The scripts are working but size and performence is different! Link to comment
Moderators IIYAMA Posted October 8, 2014 Moderators Share Posted October 8, 2014 Well it may not change the speed of the working of the code. Scripts will be loaded into the ram and will be executed. Afaik the code will be read and filtered by useful code. If you want to know if it uses less ram, check the performance browser. If you want to change the speed of the code, you need to speed up the accessing your variables and reduce the amount of functions that will be called. Link to comment
Saml1er Posted October 8, 2014 Share Posted October 8, 2014 Nah, don't worry. Just like IYAMA said simply you need to take care of variables and amount of functions. If you check race resource you'll find it kinda alien language but still you'll see that they used meta methods and I think that's really useful in those cases I mean for example, if you have 2 tables and one has all your data stored in table1 but you want to have another table with same data then you can simply use __index and leave the table empty and when you are trying to access a variable from table2 and if it is not found in table2 then __index will be triggered and it will be accessed in table1 or if it not found then it will return nil which you already know. Many people don't really care about meta methods but if you check them how they help in accessing then you'll start loving it. They also help in rendering stuff. I usually use a table for storing data instead of multiple variables. You're code is fine though and more importantly nice work ^^ 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