Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Minimizing amount of resources used


    milk1234

    Recommended Posts

    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

    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

    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

    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

    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

    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 :doge:

    Link to comment
    Share on other sites

    Archived

    This topic is now archived and is closed to further replies.

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.