roguehippo Posted August 11, 2017 Posted August 11, 2017 Hello, so im trying to make a filter that goes through all the npcs and find the one that is within 1 square of me and has a certain name. i think i got most of it right except when i go to use the list that the filter gives me, it says that it is full of "Objects" and not "NPC"s . even though i made the for npc objects. here is the filter object that i made: myFilter = new Filter<NPC>() { public boolean match(NPC obj) { return (myArea.contains(obj) && obj.getName() == "Npc name"); } }; here is where i implement it: List npcs = getNpcs().filter(myFilter); for(NPC n : npcs) { code.... } it says that "Type mismatch: cannot convert from element type Object to NPC" . sorry i dont understand filters too much i thought <NPC> would work, if anyone could help it would be appreciated
Explv Posted August 11, 2017 Posted August 11, 2017 (edited) 11 minutes ago, roguehippo said: Hello, so im trying to make a filter that goes through all the npcs and find the one that is within 1 square of me and has a certain name. i think i got most of it right except when i go to use the list that the filter gives me, it says that it is full of "Objects" and not "NPC"s . even though i made the for npc objects. here is the filter object that i made: myFilter = new Filter<NPC>() { public boolean match(NPC obj) { return (myArea.contains(obj) && obj.getName() == "Npc name"); } }; here is where i implement it: List npcs = getNpcs().filter(myFilter); for(NPC n : npcs) { code.... } it says that "Type mismatch: cannot convert from element type Object to NPC" . sorry i dont understand filters too much i thought <NPC> would work, if anyone could help it would be appreciated It returns a List<NPC> and you're storing it just as a List. You need to specify the type: List<NPC> npcs = getNpcs().filter(myFilter); Also no need to define your own Filter for this, OSBot already has predefined ones: getNpcs().closest(new NameFilter<>("NPC Name"), new AreaFilter<>(myArea)); Or if you don't care about whether it is the closest one: getNpcs().singleFilter(getNpcs().getAll(), new NameFilter<>("NPC Name"), new AreaFilter<>(myArea)); Edited August 11, 2017 by Explv
roguehippo Posted August 11, 2017 Author Posted August 11, 2017 ahhh i see , that pesky list. thank you for helping and also giving great suggestions! so helpful as always