Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

Sign up now!

Tutorial EmbeddableUI & TreeBot Tutorial/Reference

Go check out new bots and give helpful feedback.
Joined
Jan 31, 2016
Messages
5,413
Can you branch off a leaf? Like say i called a leaf to teleport somewhere, now I want it to check if its near someplace to do something else.
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
 
s̶c̶r̶i̶p̶t̶ bot*
Joined
Aug 23, 2015
Messages
2,223
Can you branch off a leaf? Like say i called a leaf to teleport somewhere, now I want it to check if its near someplace to do something else.
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.
5zpf1Ms.png
 
Niche bots at your disposal
Joined
Dec 23, 2015
Messages
1,099
I'd like to +1 the absence of the statics.UpdateUI package.
Possible to share?
 
s̶c̶r̶i̶p̶t̶ bot*
Joined
Aug 23, 2015
Messages
2,223
I'd like to +1 the absence of the statics.UpdateUI package.
Possible to share?
Why? It's only used for debugging purposes. Just replace those statements with System.out.println(arg);
 
Niche bots at your disposal
Joined
Dec 23, 2015
Messages
1,099
Why? It's only used for debugging purposes. Just replace those statements with System.out.println(arg);

Yeahhh, just figured that out. As a beginner I was doubting it was involved in updating the embedded UI (because of the UpdateUI name)
 
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:
    @Override
    public boolean validate() {
        /**
         * Validate if we see a Cow or JackO
         */
        if(targets == Targets.cow) {
            obj = Npcs.newQuery().names("Cow").within(bot.cowArea).results().nearest();

        }else if(targets == Targets.jacko) {
            obj = Npcs.newQuery().names("Jack Oval").within(bot.jackoArea).results().nearest();
        }
        System.out.println("Branch IsVisible(" + targets + "): " + (obj != null));
        return obj != null && obj.distanceTo(Players.getLocal()) <12;
    }
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:
 @Override
    public void execute() {
        if (location == TraversalLocation.cowArea)
        {area = bot.cowArea;}
        else if (location == TraversalLocation.jackoArea)
        {area = bot.jackoArea;}


        final WebPath bp = Traversal.getDefaultWeb().getPathBuilder().buildTo(area.getRandomCoordinate());
        //final BresenhamPath bp = BresenhamPath.buildTo(area.getRandomCoordinate());

        if (bp != null){
            if (bp.step(true)){
                bot.currentTaskString = "Traversing to" + location;
                Execution.delayWhile(Players.getLocal()::isMoving, 1000, 2500);
            }
        }
    }

How and why is this not working for me and does it for you?
 
s̶c̶r̶i̶p̶t̶ bot*
Joined
Aug 23, 2015
Messages
2,223
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:
Path path = nav.web.getPathBuilder().buildTo(toArea.getRandomCoordinate());
if (path != null) {
    if (bp.step(true)){
        bot.currentTaskString = "Traversing to" + location;
        Execution.delayWhile(Players.getLocal()::isMoving, 1000, 2500;
    }
} else {
    System.out.println("That bitch be null, walking with bresenham");
    bresenhamPath(toArea);
}

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

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.
 
Last edited:
Niche bots at your disposal
Joined
Dec 23, 2015
Messages
1,099
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: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:
public void execute() {
        if (location == TraversalLocation.cowArea)
        {area = bot.cowArea;}
        else if (location == TraversalLocation.jackoArea)
        {area = bot.jackoArea;}

        if (area.getRandomCoordinate() != null )
        {
            System.out.println("AreaCoordinates" + area);
            WebPath wp = Traversal.getDefaultWeb().getPathBuilder().buildTo(area.getRandomCoordinate());
            if (wp != null){
                if (wp.step(true)){
                    bot.currentTaskString = "Traversing to" + location;
                    Execution.delayWhile(Players.getLocal()::isMoving, 1000, 2500);
                }
            }
    }   }

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??
 
s̶c̶r̶i̶p̶t̶ bot*
Joined
Aug 23, 2015
Messages
2,223
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??

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.
 
Last edited:
Niche bots at your disposal
Joined
Dec 23, 2015
Messages
1,099
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
 
s̶c̶r̶i̶p̶t̶ bot*
Joined
Aug 23, 2015
Messages
2,223
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
Yea, I occasionally have to delete it due to some odd circumstances, but you shouldn't have to delete it too often.
 
Joined
Jan 29, 2017
Messages
29
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?
 
Last edited:
Joined
Jan 23, 2017
Messages
111
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?

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)
 
s̶c̶r̶i̶p̶t̶ bot*
Joined
Aug 23, 2015
Messages
2,223
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?
Your assumption is correct. When a leaf task is reached it goes back to the root branch and repeats
 
Top