Jump to content

help getting object x - myPosition x


Recommended Posts

Posted (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 by skillerkidos1
Posted
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! :D

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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