skillerkidos1 66 Posted January 15 Share Posted January 15 (edited) So I'm trying to get the X of an object in a instance and get my X while in that instance and then subtract them @Override public int onLoop() throws InterruptedException { RS2Object obj = getObjects().closest(123); int distance = myPosition().getX() - obj.getPosition().getX(); I also tried int distance = myPosition().getX() - obj.getX(); if(distance <= 2){ //do this } When I do either of those and start the script I get this error [ERROR][Bot #1][01/14 07:34:39 PM]: Error in script executor! java.lang.NullPointerException at main.onLoop(main.java:125) at org.osbot.rs07.event.ScriptExecutor$InternalExecutor.run(tk:46) at java.lang.Thread.run(Thread.java:748) I'm not really sure what I'm doing wrong any help would be great Thank you Edited January 15 by skillerkidos1 Quote Link to post Share on other sites
skillerkidos1 66 Posted January 15 Author Share Posted January 15 omg do i just need to check if they are != null first? 1 Quote Link to post Share on other sites
Gunman 437 Posted January 15 Share Posted January 15 @skillerkidos1 Pretty sure it's because something is null and you're not null checking anything. But disregarding that, does the distance api not work for what you're trying to do? int distance = getMap().distance(obj.getPosition()); Quote Link to post Share on other sites
skillerkidos1 66 Posted January 15 Author Share Posted January 15 12 minutes ago, Gunman said: @skillerkidos1 Pretty sure it's because something is null and you're not null checking anything. But disregarding that, does the distance api not work for what you're trying to do? int distance = getMap().distance(obj.getPosition()); I think I tried that but now im thinking I used it wrong Will try it now and see if that will work! Quote Link to post Share on other sites
Khaleesi 8717 Posted January 15 Share Posted January 15 9 hours ago, skillerkidos1 said: I think I tried that but now im thinking I used it wrong Will try it now and see if that will work! Always null check this kind of stuff before checking anything ^^ 1 Quote Link to post Share on other sites