Jump to content

objects.get(int, int) and groundItems.get(int, int) not working?


Recommended Posts

Posted
        int x = trapPosition.getX();
        int y = trapPosition.getY();
 
        List<RS2Object> objectsAtPos = script.objects.get(x, y);
        List<GroundItem> itemsAtPos = script.groundItems.get(x, y);
 
the last two lines give me errors: get(int, int) is not a method of Objects/groundItems.
 
        int x = trapPosition.getX();
        int y = trapPosition.getY();
 
        List<RS2Object> objectsAtPos = script.objects.getAll();
        List<GroundItem> itemsAtPos = script.groundItems.getAll();
 
does not give errors but i would like to use the first section of code.

 

Posted (edited)

I have never used filters. Can you please explain how to make and use them? It would be greatly appreciated.

Also, edit:

what you're saying is

        List<RS2Object> objectsAtPos = script.objects.filter(obj -> obj
                .getPosition().equals(trapPosition));
will return a List of RS2Objects matching trapPosition?
Edited by elliottdehn
Posted

Well you pass a Filter of a specific type to objects.filter, groundItems.filter, npcs.filter etc. A Filter has the method match, in which you specify when an object/npc/grounditem meets certain requirements. Using Java 8 lambda expressions (probably needs to be enabled in your IDE) you can specify this as:

objects.filter(variable -> requirements)

Which is the same as ( Java < 8 ):

objects.filter(
 new Filter<RS2Object>() {
   public boolean match(RS2Object variable) {
    if (requirements)
       return true;
   else return false;

  }
});

Each time you return true for a specific object/npc/grounditem it passes the filter and is added to the list, which will be returned

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