1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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 ( ͡° ͜ʖ ͡°)

    Joined:
    Mar 30, 2015
    Messages:
    2,408
    Likes Received:
    508
    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 Client Developer

    Joined:
    Oct 12, 2015
    Messages:
    3,708
    Likes Received:
    1,606
    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:
    86
    Likes Received:
    9
    You can also use LocatableEntityQueryResults

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

Share This Page

Loading...