Resolved Getting an Array of GameObjects

Discussion in 'Developer Support' started by FriendlyDev, Jul 14, 2016.

Tags:
  1. Sorry i'm pretty new to Java and i'm working on my first bot if someone could explain to me how i could get an array of nearby GameObjects so i can possibly sort them by how close they are and the by the GameObjects animation ID that would be awesome! :D

     
  2. Best Answer:
    Post #3 by Party, Jul 14, 2016
  3. in probably the simplest form:

    GameObject[] array = GameObjects.getLoaded().toArray();

    There are also methods in each of the interactable classes so you don't really have to sort them yourself. Check out the jdocs.
     
    #2 Serene, Jul 14, 2016
    Last edited: Jul 14, 2016
  4. Code (Text):
    1. GameObjects.newQuery().filter(new Predicate(){
    2.       private boolean test(GameObject o){
    3.             return o.getAnimationId() == your animation id;
    4.       }
    5. }).results().sortByDistance();
     
  5. You can also use LocatableEntityQueryResults

    Code (Text):
    1. LocatableEntityQueryResults results = GameObjects.newQuery().results();
     

Share This Page

Loading...