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
  • Try asking for help in the chatbox
  • best approach to dealing with gameobject?


    sergbot
     Share

    Recommended Posts

    if (!Inventory.contains("Logs") && (GameObjects.closest("Fire") == null || GameObjects.closest("Fire").distance() > 10)) {

     

    So basically, i would check if a fire exists using "fire" ==

    However, sometimes the client glitches out, and it says that the fire isnt null and that the distance is like 50.

    However if i just use .distance is less than 12, then it throws an npe if the fire object is actually null.

    So i need to check if its null, or if it's not null and the distance is less than 50. 

     

     

    Link to comment
    Share on other sites

    damn, im retarded, i can just do

    if (!Inventory.contains("Logs") && (GameObjects.closest("Fire") == null || (GameObjects.closest("Fire") != null && GameObjects.closest("Fire").distance() > 10))) {

    Link to comment
    Share on other sites

    I would recommend using a filter. For example:
     

    GameObjects.closest(object -> object.getName.equals("Fire") && fire != null && fire.distance > 10);

    Simplifies your code significantly

    Link to comment
    Share on other sites

    5 hours ago, crazykid080 said:

    I would recommend using a filter. For example:
     

    GameObjects.closest(object -> object.getName.equals("Fire") && fire != null && fire.distance > 10);

    Simplifies your code significantly

    this wouldnt work in his case, and the syntax is wrong.  he wants to check if it is null or if it is further than 10

     

    if(!Inventory.contains("Logs") && GameObjects.closest(gameObject -> gameObject.getName().equals("Fire") && gameObject.distance() < 10) == null) {
                                do stuff
    }

     

    Link to comment
    Share on other sites

    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
     Share

    ×
    ×
    • 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.