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

Tutorial EmbeddableUI & TreeBot Tutorial/Reference

Discussion in 'Tutorials & Resources' started by proxi, Apr 6, 2016.

  1. Serene

    Serene ( ͡° ͜ʖ ͡°)

    Joined:
    Mar 30, 2015
    Messages:
    2,408
    Likes Received:
    508
    You could use a branch to check if it is near something else.
     
  2. awesome123man

    awesome123man Go check out new bots and give helpful feedback.

    Joined:
    Jan 31, 2016
    Messages:
    5,413
    Likes Received:
    1,662
    Leafs are at the end of your binary tree. So as serene said, you would need a Branch to check if you are near somewhere. But you cannot branch off a leaf :p
     
  3. proxi

    proxi s̶c̶r̶i̶p̶t̶ bot*

    Joined:
    Aug 23, 2015
    Messages:
    2,223
    Likes Received:
    501
    You'd have to change up your tree it sounds like.

    Most likely need to have a validater determining if you've teleported or not within a branch task. Based on that result, do what you need to do.
    [​IMG]
     
    awesome123man and Slex like this.
  4. tyb51

    tyb51 Niche bots at your disposal

    Joined:
    Dec 23, 2015
    Messages:
    1,099
    Likes Received:
    439
    I'd like to +1 the absence of the statics.UpdateUI package.
    Possible to share?
     
  5. proxi

    proxi s̶c̶r̶i̶p̶t̶ bot*

    Joined:
    Aug 23, 2015
    Messages:
    2,223
    Likes Received:
    501
    Why? It's only used for debugging purposes. Just replace those statements with System.out.println(arg);
     
  6. tyb51

    tyb51 Niche bots at your disposal

    Joined:
    Dec 23, 2015
    Messages:
    1,099
    Likes Received:
    439
    Yeahhh, just figured that out. As a beginner I was doubting it was involved in updating the embedded UI (because of the UpdateUI name)
    --- Double Post Merged, Apr 3, 2017, Original Post Date: Apr 2, 2017 ---
    I have another question:

    I don't understand the way the Traverse method works (and as a matter of facts: it does not work for me)
    In the traverse leaf you use an if/else if statement. But when calling the 'final BresenhamPath' is see no reason why this line, and the lines below are separated from the else if statement.

    In fact I'm having trouble with the if statements in general. It seems that no actions after the if/elseif are being excecuted: e.g.
    Code (Text):
    1.     @Override
    2.     public boolean validate() {
    3.         /**
    4.          * Validate if we see a Cow or JackO
    5.          */
    6.         if(targets == Targets.cow) {
    7.             obj = Npcs.newQuery().names("Cow").within(bot.cowArea).results().nearest();
    8.  
    9.         }else if(targets == Targets.jacko) {
    10.             obj = Npcs.newQuery().names("Jack Oval").within(bot.jackoArea).results().nearest();
    11.         }
    12.         System.out.println("Branch IsVisible(" + targets + "): " + (obj != null));
    13.         return obj != null && obj.distanceTo(Players.getLocal()) <12;
    14.     }
    I can't debug this, it returns false everytime and does not put out a println. As you can see in the code I tried adding curly brackets to the different statements with no succes.

    In the traverse Excecute code: I'm even getting NullReferenceErrors which crash the bot:
    Code (Text):
    1.  @Override
    2.     public void execute() {
    3.         if (location == TraversalLocation.cowArea)
    4.         {area = bot.cowArea;}
    5.         else if (location == TraversalLocation.jackoArea)
    6.         {area = bot.jackoArea;}
    7.  
    8.  
    9.         final WebPath bp = Traversal.getDefaultWeb().getPathBuilder().buildTo(area.getRandomCoordinate());
    10.         //final BresenhamPath bp = BresenhamPath.buildTo(area.getRandomCoordinate());
    11.  
    12.         if (bp != null){
    13.             if (bp.step(true)){
    14.                 bot.currentTaskString = "Traversing to" + location;
    15.                 Execution.delayWhile(Players.getLocal()::isMoving, 1000, 2500);
    16.             }
    17.         }
    18.     }
    How and why is this not working for me and does it for you?
     
  7. proxi

    proxi s̶c̶r̶i̶p̶t̶ bot*

    Joined:
    Aug 23, 2015
    Messages:
    2,223
    Likes Received:
    501
    Okay to start this off there's a couple of things you'll want to do first just for optimization sake.

    In the below spoiler you're calling to retrieve the web Each Time this this leaf of the loop is executed. You could rather on startup retrieve the default web and save it as a public variable. Also, this does not need to be final in this case (this may be where your issue with traversal resides).
    final WebPath bp = Traversal.getDefaultWeb().getPathBuilder().buildTo(area.getRandomCoordinate());

    Once you have that stored as an accessible variable you could do something like so...
    Code (Text):
    1.  
    2. Path path = nav.web.getPathBuilder().buildTo(toArea.getRandomCoordinate());
    3. if (path != null) {
    4.     if (bp.step(true)){
    5.         bot.currentTaskString = "Traversing to" + location;
    6.         Execution.delayWhile(Players.getLocal()::isMoving, 1000, 2500;
    7.     }
    8. } else {
    9.     System.out.println("That bitch be null, walking with bresenham");
    10.     bresenhamPath(toArea);
    11. }
    12.  

    In your initial spoiler you talk about your validator always returning false. Why not just debug it a little more?
    Code (Text):
    1.     @Override
    2.     public boolean validate() {
    3.         /**
    4.          * Validate if we see a Cow or JackO
    5.          */
    6.         if(targets == Targets.cow) {
    7.             obj = Npcs.newQuery().names("Cow").within(bot.cowArea).results().nearest();
    8.         }else if(targets == Targets.jacko) {
    9.             obj = Npcs.newQuery().names("Jack Oval").within(bot.jackoArea).results().nearest();
    10.         }
    11.         System.out.println("obj(" + targets + ") != null: " + (obj != null));
    12.         System.out.println("obj(" + targets + ").distanceTo(Players.getLocal()): " + (obj.distanceTo(Players.getLocal()) <12));
    13.         return obj != null && obj.distanceTo(Players.getLocal()) <12;
    14.     }

    If your object is continuously null, why not try taking off the "within(area)" part of your query, it's possible that you may have your area set up incorrectly. You could also avoid this by null-checking the areas and having a corresponding query for each case (probably undesired, but you could do it lol).


    For the most part, it seems like you have the majority of what you need to grasp in order to make a bot, you just need to improve in debugging your code.
     
    #27 proxi, Apr 3, 2017
    Last edited: Apr 3, 2017
  8. tyb51

    tyb51 Niche bots at your disposal

    Joined:
    Dec 23, 2015
    Messages:
    1,099
    Likes Received:
    439
    Hey, I think I didn't explain enough what I meant I don't understand.
    In my first spoiler with targets, it does not report the println in the console. SO I can't actually debug if my areas are false. What this implicates is that no lines are run after an if/else if statement. So no debug lines and no return lines (I suppose, not sure of that) Because no returnvalue is put out. I suspect it always returns failureTask (null=false?)?

    Same for the traversal script bot:If I comment out everything after the if/else statement it gives no errors. If I add any lines after it, even by using an other if-function as in the example below, it gives a NullPointerException on the first line after the if/end if.
    Code (Text):
    1. public void execute() {
    2.         if (location == TraversalLocation.cowArea)
    3.         {area = bot.cowArea;}
    4.         else if (location == TraversalLocation.jackoArea)
    5.         {area = bot.jackoArea;}
    6.  
    7.         if (area.getRandomCoordinate() != null )
    8.         {
    9.             System.out.println("AreaCoordinates" + area);
    10.             WebPath wp = Traversal.getDefaultWeb().getPathBuilder().buildTo(area.getRandomCoordinate());
    11.             if (wp != null){
    12.                 if (wp.step(true)){
    13.                     bot.currentTaskString = "Traversing to" + location;
    14.                     Execution.delayWhile(Players.getLocal()::isMoving, 1000, 2500);
    15.                 }
    16.             }
    17.     }   }

    How then can I make it so that in 1 execute or validate function I can first set a variable (the Area) according to the input i give to the function (cow of jacko) with an If/elseIf followed by the execution of my webpath

    PS: I read by cloud that recalling webpath for every action is good for enhancement of the system????? Btw if intitializing before hand For X locations I'd need X Webpath variables??
     
  9. proxi

    proxi s̶c̶r̶i̶p̶t̶ bot*

    Joined:
    Aug 23, 2015
    Messages:
    2,223
    Likes Received:
    501
    You don't initialize X locations for X webpaths, you initialize the web and then generate the path as needed. The pathing would work the exact way you currently have it set up, except you'd be accessing your local instance of the web.

    If your print outs are not ouputting anything to your console then I can only think of a couple things to do.

    1) Make 100% certain that this code is even running. Trace your root task and through all of the conditions. Create printouts at each branch validator so you can see how your code is progressing through your branches.

    2) If you think the above is already correct then try deleting your "out" folder and recompiling.
     
    #29 proxi, Apr 3, 2017
    Last edited: Apr 3, 2017
    tyb51 likes this.
  10. tyb51

    tyb51 Niche bots at your disposal

    Joined:
    Dec 23, 2015
    Messages:
    1,099
    Likes Received:
    439
    I finally found out what the problem was. I had a typo in my UI controller, which indeed didn't assign the right areas -.-. Something you said before did made me think of it! Everything works now! Fieeww, good for learning.
    The thing that helped me most tho was deleting the out folder now and then. The bot tends do do some weird things now and then
     
  11. proxi

    proxi s̶c̶r̶i̶p̶t̶ bot*

    Joined:
    Aug 23, 2015
    Messages:
    2,223
    Likes Received:
    501
    Yea, I occasionally have to delete it due to some odd circumstances, but you shouldn't have to delete it too often.
     
  12. Ap0kalypsis

    Joined:
    Jan 29, 2017
    Messages:
    29
    Likes Received:
    2
    In the original example when it executes a leaf does it automatically go back to the is Inventory Full branch once the leafs condition has been accomplished? Example being if the inventory is not full, it checks if the bank is open. The bank is not open so it traverses to the flax area. Does it go back to is Inventory Full to then check if the bank is open to then go to is Flax Nearby?
     
    #32 Ap0kalypsis, Apr 6, 2017
    Last edited: Apr 6, 2017
  13. Slex

    Joined:
    Jan 23, 2017
    Messages:
    111
    Likes Received:
    19
    When the leaf is done, it will go back to the root. Depending on what you have in the leaf of course (if the code is to stop the bot due to an error you won't get back to the root of course)
     
  14. proxi

    proxi s̶c̶r̶i̶p̶t̶ bot*

    Joined:
    Aug 23, 2015
    Messages:
    2,223
    Likes Received:
    501
    Your assumption is correct. When a leaf task is reached it goes back to the root branch and repeats
     
    Ap0kalypsis and Slex like this.

Share This Page

Loading...