Antoff_livin 0 Share Posted July 10, 2020 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 More sharing options...
Pandemic 2675 Share Posted July 10, 2020 You aren't checking if the ground item exists when you try to take it. Link to comment Share on other sites More sharing options...
Antoff_livin 0 Author Share Posted July 11, 2020 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 More sharing options...
Antoff_livin 0 Author Share Posted July 11, 2020 Never mind, I figured it out! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.