Jack Posted July 5, 2014 Share Posted July 5, 2014 groundItems.getAll() gets a list of all ground items How do I do this for entites? I looked all over the api and I have found nothing Link to comment Share on other sites More sharing options...
Botre Posted July 5, 2014 Share Posted July 5, 2014 Get all NPCs Get all RS2Objects Add both to a list Done Link to comment Share on other sites More sharing options...
Jack Posted July 5, 2014 Author Share Posted July 5, 2014 Get all NPCs Get all RS2Objects Add both to a list Done how do i get all rs2objects? Thats what I need. Link to comment Share on other sites More sharing options...
Botre Posted July 5, 2014 Share Posted July 5, 2014 how do i get all rs2objects? Thats what I need. script.getObjects().getAll(); Link to comment Share on other sites More sharing options...
Jack Posted July 5, 2014 Author Share Posted July 5, 2014 script.getObjects().getAll(); this returns 7642 objects. Looping through all of them to find the ones near me takes a few seconds for some reason. Is there a reason for that? Link to comment Share on other sites More sharing options...
Botre Posted July 5, 2014 Share Posted July 5, 2014 (edited) this returns 7642 objects. Looping through all of them to find the ones near me takes a few seconds for some reason. Is there a reason for that? Depends on how you are looping an what you are checking the objects for. Edited July 5, 2014 by Botrepreneur Link to comment Share on other sites More sharing options...
Jack Posted July 5, 2014 Author Share Posted July 5, 2014 Depends on how you are looping an what you are checking the objects for. for(int i = 0; i < objects.getAll().size(); i++){ if(objects.getAll().get(i)!=null&&posDist(myPosition(),objects.getAll().get(i).getPosition())<5&&!objects.getAll().get(i).getName().equals("null")) //add to bigger list } Link to comment Share on other sites More sharing options...
Botre Posted July 5, 2014 Share Posted July 5, 2014 for(int i = 0; i < objects.getAll().size(); i++){ if(objects.getAll().get(i)!=null&&posDist(myPosition(),objects.getAll().get(i).getPosition())<5&&!objects.getAll().get(i).getName().equals("null")) //add to bigger list } Every time you call objects.getAll() it will rescan for objects to create a new list. That's why it's slow. Call it once instead, save the list obtained and filter through that one list. Link to comment Share on other sites More sharing options...
Jack Posted July 5, 2014 Author Share Posted July 5, 2014 Every time you call objects.getAll() it will rescan for objects to create a new list. That's why it's slow. Call it once instead, save the list obtained and filter through that one list. Oh thanks I overlooked that :P It took a few seconds because it was loading them 7000 times :P Link to comment Share on other sites More sharing options...
Mysteryy Posted July 5, 2014 Share Posted July 5, 2014 Oh thanks I overlooked that It took a few seconds because it was loading them 7000 times When you are null checking or interacting with an item/object etc. you should always store it, and then interact with the stored object. Each time you call .get() it will get a new instance, and that instance could be not null, then when you go to interact with another .get() it can be null. If that makes sense. Although you may have already knew this and just forgot or not noticed it. ^_^ Link to comment Share on other sites More sharing options...
Jack Posted July 5, 2014 Author Share Posted July 5, 2014 When you are null checking or interacting with an item/object etc. you should always store it, and then interact with the stored object. Each time you call .get() it will get a new instance, and that instance could be not null, then when you go to interact with another .get() it can be null. If that makes sense. Although you may have already knew this and just forgot or not noticed it. Yea I was just writing it too fast and forgot Link to comment Share on other sites More sharing options...
Mysteryy Posted July 5, 2014 Share Posted July 5, 2014 Yea I was just writing it too fast and forgot Happens to me 9/10 times xD Link to comment Share on other sites More sharing options...