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
  • Debug Console Error Unknown


    Antoff_livin

    Recommended Posts

    Hello I am fairly new and I am having problems with a script. It used to work fine but now I am getting random errors. One in particular keeps showing up, but I don't understand what it means.

    The overall script is just picking items up, then waiting until they spawn again, and then doing that until the inventory is full or it runs out of food. I am currently using a while loop to do so within the onLoop (I know, not supposed to but can't figure out how else to do it).

    The error is below.

    • [ERROR]16:25:41: Exception has occurred while running! Please report error to developer if problem persists: java.lang.NullPointerException at Test.Main.onLoop(Main.java:32) at org.dreambot.api.script.AbstractScript.run(AbstractScript.java:264) at java.lang.Thread.run(Unknown Source)

    Forgive how messy the code is as well, but I have been trying to debug this for a while so cleaning it will be later. Code is below:

    public void health(){
            if (getCombat().getHealthPercent() < 50) {
                getTabs().openWithMouse(Tab.INVENTORY);
                sleep(Calculations.random(100, 300));
                getInventory().interact(379, "Eat");
            }
    
        }
        @Override
        public int onLoop() {
           
            while(!getInventory().isFull()){
                int food = getInventory().count(food);
                getGroundItems().closest(stuff).interact("Take");
                sleep(200);
                health();
                if(getGroundItems().closest(stuff) == null){
                    getWalking().walk(tile);
                    health();
                }
                if(food < 2 || getInventory().isFull()) {
                    break;
                }
                health();
                sleep(Calculations.random(900,1300));
            }
            stop();
            return 10000;
        }
    }
    Link to comment
    Share on other sites

     

    1 hour ago, Pandemic said:

    You aren't checking if the ground item exists when you try to take it.

    How would I do that correctly then? Also, when I turn this into a for loop (that doesn't accomplish what is needed) I don't get this error. I've been beating my head against the desk for a while trying to not use a while loop, but I don't know of a way to get past it.

    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.