Resolved Getting an Array of GameObjects

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

Tags:
  1. FriendlyDev

    Joined:
    Jul 8, 2016
    Messages:
    1
    Likes Received:
    0
    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. Serene

    Serene Premium Author

    Joined:
    Mar 30, 2015
    Messages:
    664
    Likes Received:
    139
    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. Party

    Party The Favourite

    Joined:
    Oct 12, 2015
    Messages:
    2,095
    Likes Received:
    755
    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. Twinki

    Joined:
    Sep 30, 2015
    Messages:
    77
    Likes Received:
    9
    You can also use LocatableEntityQueryResults

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

Share This Page

Loading...