Jump to content

help getting object x - myPosition x


skillerkidos1

Recommended Posts

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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