Jump to content
Jack

List of entities

Recommended Posts

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

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.


  • Recently Browsing   0 members

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