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

Question NewQuery() usage

Discussion in 'Developer Support' started by sefzer, Aug 5, 2016.

  1. sefzer

    Joined:
    Jul 28, 2016
    Messages:
    13
    Likes Received:
    0
    Hello,

    I've made a fletching bot succesfully with the state method and I've also managed to make a good GUI for it using embeddableUI and SceneBuilder.
    I'm, however, having a hard time understanding newQuery(). In my bot for example, I have a menu option for the type of log to use and which item to make.

    Now the options for the item are "Arrow shaft", "shortbow", "stock" and "shieldbow". If, for example, "shortbow" is selected I want to find the option for the shortbow in the make x interface. The problem here is I only have part of the name "Maple shortbow" so I have to find the option which contains a item which has "shortbow" in it's name and click it. Currently I'm using Interfaces.getAt() to get the interface container and component then i have a for loop to go through each subcomponent and see which contains the item which has "shortbow" in it's name and click it. I want to find the option by it's partial name so that the user doesn't need to type the name in the menu nor do I have to get full names od the items myself to have to write them down.

    I'm willing to contribute to the community and make bots, but I want to make sure I'm using the most efficient and proper coding first. If someone could also shortly explain or give examples of predicates and newQuery() I'd appreciate it.
     
    #1 sefzer, Aug 5, 2016
    Last edited: Aug 5, 2016
  2. Party

    Party Client Developer

    Joined:
    Oct 12, 2015
    Messages:
    3,708
    Likes Received:
    1,606
    Hi,

    First off you should join the #development channel on Slack.

    Secondly, you can use .#newQuery().texts() with regards to interfaces. You should familiarise yourself with the JDocs. Predicates essentially just validate an object using a boolean and, if it returns true, add it to the list of results. Example usage:
    Code (Text):
    1. Npc yak = Npcs.newQuery().names("Yak").actions("Attack").within(yaks.getYakPen()).filter(new Predicate<Npc>() {
    2.             @Override
    3.             public boolean test(Npc npc) {
    4.                 return npc.getTarget() == null
    5.                         && npc.getHealthGauge() == null;
    6.             }
    7. }).results().first();
    I believe there was also functionality added in the last release with regards to the MakeX interface, courtesy of @SlashnHax.
     

Share This Page

Loading...