Jump to content

Conditional Sleep while mining NullPointerException


Protoprize

Recommended Posts

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)

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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();
        }

 

Link to comment
Share on other sites

  • 2 years later...
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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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