Jump to content

Conditional Sleep while mining NullPointerException


Recommended Posts

Posted

Sooo.... I've spent a while away from making scripts but since I finally have time to work on some stuff, I've decided to make a simple motherload miner 

The code is mostly done and I'm planning to release it at some point, but I only have one problem....

                RS2Object oreDeposit = api.getObjects().closest("Ore vein");
                String objectName = oreDeposit.getName();
                int objectModelID = oreDeposit.getId();
                if(api.getMap().canReach(oreDeposit)) {
                    oreDeposit.interact("Mine");
                    api.log("Waiting to be done mining");
                    new ConditionalSleep(6000, 8000) {
                        @Override
                        public boolean condition() {
                            return !api.getObjects().closest(objectModelID).getName().equals("Ore vein");
                        }
                    }.sleep();

I've made this simple conditional sleep, which checks the model ID of the previously saved object, and compares it to what it expected to be there while the ore is mineable, 

All is good while it is still called 'ore vein', but after it depletes, it starts freaking out (I have to force close it) with a NullPointerException

 

I've checked the modeID before and after it has depleted, and it does not change, therefore I am here to see what you guys suggest! Or I accept being absolutely retarded (it do be like that sometimes)

Posted (edited)
2 hours ago, HeyImJamie said:

You need to null check. The NPE thrown will direct you to where. :)

 

 

I've added check for it and now the error is gone???????? No output or anything even when using 

 catch (NullPointerException e) {
                    api.log(e.getMessage());
                }

Decided to split two functions and now it works :/ 

I still have no idea how I fixed it 😧

Edited by Protoprize
Posted
RS2Object oreDeposit = getObjects().closest("Ore vein");
        String objectName = oreDeposit.getName();
        int objectModelID = oreDeposit.getId();
        if(oreDeposit != null && getMap().canReach(oreDeposit)) {
            oreDeposit.interact("Mine");
            log("Waiting to be done mining");
            new ConditionalSleep(6000, 8000) {
                @Override
                public boolean condition() {
                    return getObjects().closest(objectModelID) != null && getObjects().closest(objectModelID).getName().equals("Ore vein");
                }
            }.sleep();
        }

 

  • 2 years later...
Posted
On 12/15/2019 at 10:33 AM, FuryShark said:
RS2Object oreDeposit = getObjects().closest("Ore vein");
        String objectName = oreDeposit.getName();
        int objectModelID = oreDeposit.getId();
        if(oreDeposit != null && getMap().canReach(oreDeposit)) {
            oreDeposit.interact("Mine");
            log("Waiting to be done mining");
            new ConditionalSleep(6000, 8000) {
                @Override
                public boolean condition() {
                    return getObjects().closest(objectModelID) != null && getObjects().closest(objectModelID).getName().equals("Ore vein");
                }
            }.sleep();
        }

 

Tried this and it still spam clicks the ore vein :(

Untitled.png

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...