Jump to content

List of entities


Recommended Posts

Posted

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

Posted

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

Posted

Oh thanks I overlooked that tongue.png

 

It took a few seconds because it was loading them 7000 times tongue.png

 

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

Posted

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

Yea I was just writing it too fast and forgot facep.gif

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...