maxibaby Posted January 3, 2016 Share Posted January 3, 2016 (edited) I'm trying to get all the objects of various id's inside an area. I was trying to getObjects().filter(new IdFilter(id),new AreaFilter(area)); But getting many repeated objects? Another question: For example, when i chop a tree, and i have an object, when it grows up, is the same object with different model, or is a new object Edited January 3, 2016 by maxibaby Quote Link to comment Share on other sites More sharing options...
Token Posted January 3, 2016 Share Posted January 3, 2016 There are 2 ways to do this 1. Using OSBot Filter API List<RS2Object> objs = objects.filter(new Filter<RS2Object>() { @Override public boolean match(RS2Object o) { return o.getId() == ID && AREA.contains(o); } }); 2. Using lambda expressions RS2Object[] objs = objects.getAll().stream().filter(o -> o.getId() == ID && AREA.contains(o)).toArray(RS2Object[]::new); First one returns a list, while the second returns an array. That doesn't make much difference if you know how to use them. As for your second question, I'm pretty sure it's the same object, hence we have an exists() method in the API which is used to check if that object still exists. Quote Link to comment Share on other sites More sharing options...
Explv Posted January 3, 2016 Share Posted January 3, 2016 (edited) RS2Object[] objs = objects.getAll().stream().filter(o -> o.getId() == ID && AREA.contains(o)).toArray(RS2Object[]::new); This can be done in a shorter way: RS2Object[] objects = getObjects().filter(obj -> obj.getId() == ID && AREA.contains(obj)); Usually what you want to do is find the closest object, for example to find the closest Willow tree in a specified Area: RS2Object willowTree = getObjects().closest(obj -> obj.getName().equals("Willow") && AREA.contains(obj)); Edited January 5, 2016 by Explv 1 Quote Link to comment Share on other sites More sharing options...
maxibaby Posted January 4, 2016 Author Share Posted January 4, 2016 (edited) Can you please explain to me what are you doing. From what i read on api http://osbot.org/api/org/osbot/rs07/api/filter/FilterAPI.html#filter-java.util.Collection-org.osbot.rs07.api.filter.Filter...- Signature is filter(Filter<E>... filters) So, what are you guys passing as parameter? Edited January 4, 2016 by maxibaby Quote Link to comment Share on other sites More sharing options...
Explv Posted January 4, 2016 Share Posted January 4, 2016 (edited) Can you please explain to me what are you doing. From what i read on api http://osbot.org/api/org/osbot/rs07/api/filter/FilterAPI.html#filter-java.util.Collection-org.osbot.rs07.api.filter.Filter...- Signature is filter(Filter<E>... filters) So, what are you guys passing as parameter? I am just using lambda expressions as it shortens your code significantly: http://tutorials.jenkov.com/java/lambda-expressions.html This: getObjects().filter(obj -> obj.getId() == ID && AREA.contains(obj)); Is equivalent to: getObjects().filter(new Filter<RS2Object>() { @Override public boolean match(RS2Object obj) { return obj.getId() == ID && AREA.contains(obj); } }); Edited January 4, 2016 by Explv Quote Link to comment Share on other sites More sharing options...
Joseph Posted January 5, 2016 Share Posted January 5, 2016 Can you please explain to me what are you doing. From what i read on api http://osbot.org/api/org/osbot/rs07/api/filter/FilterAPI.html#filter-java.util.Collection-org.osbot.rs07.api.filter.Filter...- Signature is filter(Filter<E>... filters) So, what are you guys passing as parameter? that parameter uses your array of filters not as one but instead separately. It will return the first found filter. for example: getInventory().getItem(string...array); will return the first found item by name. just because you added different 2 filters does not mean it will combine them into one. RS2Object[] objects = getObjects().closest(obj -> obj.getName().equals("Willow") && AREA.contains(obj)); should be RS2Object objects = getObjects()............... the rest. not array Quote Link to comment Share on other sites More sharing options...