Im A Baller 348 Posted March 15, 2017 What do I need to nullcheck? I just added nullchecks to everything in the case but its still doing that. rock1 and rock2. if it's null, you can't use .exists() http://stackoverflow.com/questions/19336608/what-does-null-mean
Certified7 0 Posted March 16, 2017 First, I would recommend null checking your rocks in your filter like so: GameObject rock1 = getGameObjects().closest(GameObject -> GameObject != null && (GameObject.getID() == 7487) && GameObject.distance(getLocalPlayer()) < 3); GameObject rock2 = getGameObjects().closest(GameObject -> GameObject != null && (GameObject.getID() == 7454) && GameObject.distance(getLocalPlayer()) < 3); Edit: It occured to me that you might also want to null check in your if statement, in case another player mines the rock before you interact with it. //filters up here if (rock1 != null && rock1.isOnScreen()) { //isOnScreen() might be isVisible() instead, I can't remember - however, this is redundant since your filter only looks for rocks a max of 2 tiles away rock1.interact(); } For future reference, if you have a script that has to throw NPEs (a mining script shouldn't): For example, I have a script that changes location randomly and throws NPEs all over the place. Use try/catch blocks when NPEs are unavoidable. //a way to gracefully handle exceptions try { //put your code that throws the exception here } catch (NullPointerException e) { log("Caught (" + String.valueOf(e) + ")"); //delete this after testing break; //or some other exit condition check if the NPE is thrown in a loop, you can also just leave the catch block blank, or sleep } Let me know if you need more help.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.