Jump to content

Objects.get(ln:138) ArrayIndexOutOfBoundsException: -156


Recommended Posts

Posted
java.lang.ArrayIndexOutOfBoundsException: -156
at org.osbot.rs07.api.Objects.get(ln:138)
at ChefBot.onLoop(ChefBot.java:107)
at org.osbot.rs07.event.ScriptExecutor$InternalExecutor.run(ao:83)
at java.lang.Thread.run(Unknown Source)

Offending line:
List<RS2Object> doorTile = objects.get(3242, 3212);

Am I doing something wrong or is this a bug?

 
Posted (edited)

Why are you making a list for one tile?

Edit: okay, that's pretty weird. I never had to make a list for the position.. here's a quick mock-up. It worked for me. You always have to null check.

 

6zHSqpl.png

You didn't try my coordinates. I'm using the same code.. The list is the only way to get the object that that coords, there can be multiple objects per coordinate, up to 10.

Edited by dmm_slaver
Posted

very strange... if you can't get this to work, maybe use something like this in the meantime:

 

List<RS2Object> getObjectsAt(int x, int y) {

      List<RS2Object> objects = new ArrayList<>();

      for(RS2Object o: objects.getAll()) {

            if(o != null && o.getPosition().getX() == x && o.getPosition().getY() == y) {

                  objects.add(o);

            }

      }

      return objects;

}

Posted

You didn't try my coordinates. I'm using the same code.. The list is the only way to get the object that that coords, there can be multiple objects per coordinate, up to 10.

Well, I'm not exactly where you're at, so it's rather pointless to try your coords.

Also, post more of the script. One line doesn't really help us in helping you much.

 

Here's another filter if @@Khaleesi's didn't work out for you.

Entity doors = objects.getAll().stream().filter(n -> n.getName().equals("Door") && n.getX() == 1234 && n.getY() == 1234 && n.getModel().equals(1234)).findFirst().get();

You can put in x, y coords, add in model number if it's a different object, or you can remove that part and simply change the getname string.

Posted

very strange... if you can't get this to work, maybe use something like this in the meantime:

 

List<RS2Object> getObjectsAt(int x, int y) {

      List<RS2Object> objects = new ArrayList<>();

      for(RS2Object o: objects.getAll()) {

            if(o != null && o.getPosition().getX() == x && o.getPosition().getY() == y) {

                  objects.add(o);

            }

      }

      return objects;

}

I tried that, and the door is NOT in the list. I am assuming because of the same error that is causing the exception i experienced. 

Posted

According to the stacktrace the offending line is not in your code. If your code meets common sense standards such as following the API documentation on that method, what you encounter is an error in the API. The only error you can produce on your side with that code is by attempting to call it for a x-y pair which is not on the minimap. If this is not the case feel free to make a thread in the Client Bugs & Suggestions section.

 

 

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...