milk1234 1 Share Posted June 18, 2019 When writing scripts, no matter how simple or complex, what would be the way to minimize the number of resources used? For example, if we suppose that having a nested if statement uses more RAM/CPU than using multiple lines of divided if statements, we'd go for the latter when writing such a script. Of course, the highest priority should be in making sure the script works and doesn't break easily, but after that, what would be some minor/major adjustments you could make? Link to comment Share on other sites More sharing options...
NovaGTX 106 Share Posted June 18, 2019 Do you know how programming works? Using a nested if statement would use less RAM if it could exit on the first condition. Pro tip: Create an additional thread and nest 19 while loops to check every ground item that your client has rendered. Link to comment Share on other sites More sharing options...
milk1234 1 Author Share Posted June 18, 2019 " If we suppose" Link to comment Share on other sites More sharing options...
NovaGTX 106 Share Posted June 18, 2019 8 hours ago, milk1234 said: " If we suppose" Well your assumption is wrong, and if you genuinely want advice I’d focus more on understanding rather than optimization at this point. To answer your question, I’d always recommend a for loop if you know the number of iterations you need rather than a while loop. Don’t call the getState() function directly in your onloop or in your paint, instead create a variable and assign the state function to your variable. Link to comment Share on other sites More sharing options...
Nuclear Nezz 2061 Share Posted June 18, 2019 Sort of as Nova* said, assign variables any time you can, rather than re-calling the same function over and over. Cache certain variables if you are able to as well, so that even when you do re-call the method, it doesn't go through all of the effort to return a variable you know doesn't have to be updated every second. Instead of doing something like if(animating)return 100; if you know the animation is going to last for at least 1200ms, sleep for 1000ms, you just cut off 10 calls you would have otherwise made for no reason. Try to pinpoint areas of your code that are clearly going to use more resources than others, and see if you can restructure it to fit the points above. Link to comment Share on other sites More sharing options...
NovaGTX 106 Share Posted June 19, 2019 19 hours ago, Nuclear Nezz said: Sort of as Nex said, assign variables any time you can, rather than re-calling the same function over and over. Cache certain variables if you are able to as well, so that even when you do re-call the method, it doesn't go through all of the effort to return a variable you know doesn't have to be updated every second. Instead of doing something like if(animating)return 100; if you know the animation is going to last for at least 1200ms, sleep for 1000ms, you just cut off 10 calls you would have otherwise made for no reason. Try to pinpoint areas of your code that are clearly going to use more resources than others, and see if you can restructure it to fit the points above. I think you meant Nova instead of Nex but it’s okay Link to comment Share on other sites More sharing options...
Nuclear Nezz 2061 Share Posted June 19, 2019 4 hours ago, NovaGTX said: I think you meant Nova instead of Nex but it’s okay l0l my bad friend, all I remembered was the N, could've sworn it was Nex. edit: idk what you mean I had nova the whole time Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.