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

Question Tree bot - Check is fully logged in

Discussion in 'Developer Support' started by theSmeg, Jul 5, 2019.

  1. theSmeg

    Joined:
    Jun 25, 2019
    Messages:
    24
    Likes Received:
    5
    So i'm having an issue similar to this thread -> Resolved - [OSRS] Runescape.isLoggedIn() = true in "lobby screen"?

    The thing is im using a tree bot instead of a looping bot. I have structured my bot so that if it can't find a fishing spot it logs out. The problem being the fishing spot is not visible until I log in completely. However runemate executes all of my logic before the login handler has logged me completely in e.g clicked through the "lobby".

    My question is what is the best way using a tree bot structure to check if a player is completely logged in?

    I have tried:
    - delayUntil in the branch that checks if i'm near a fishing spot -> didnt work, it returned a null pointer exception on Execution.delayUntil(() -> p.isVisible());

    Code (Text):
    1. public class IsNearFishSpot extends BranchTask {
    2.  
    3.     private Fish fish = new Fish();
    4.     private Logout logout = new Logout();
    5.  
    6.     private Npc fishing_spot;
    7.     private Player p;
    8.  
    9.     @Override
    10.     public boolean validate() {
    11.         fishing_spot = Npcs.newQuery().names("Fishing spot").actions("Net").results().nearest();
    12.         p = Players.getLocal();
    13.         Execution.delayUntil(() -> p.isVisible());
    14.         if (fishing_spot != null) {
    15.             return true;
    16.         } else {
    17.             return false;
    18.         }
    19.  
    20.     }
    21.  
    22.  
    23.     @Override
    24.     public TreeTask failureTask() {
    25.         return logout;
    26.     }
    27.  
    28.     @Override
    29.     public TreeTask successTask() {
    30.         return fish;
    31.     }
    32. }
    - I've tried doing this check in the root node but im not sure what to return outside of the if statement:

    Code (Text):
    1.  
    2. public class PowaFisher extends TreeBot {
    3.     private Player p;
    4.  
    5.     @Override
    6.     public TreeTask createRootTask() {
    7.         if ((p = Players.getLocal()) == null || !p.isVisible()) {
    8.             return new IsInventoryFull();
    9.         }
    10.         return null; // is it ok to return null? whats the proper return statement here?
    11.     }
    12.  
    So yeah not sure how to properly check that im logged in so that I can start looping through my bot logic.
     
    #1 theSmeg, Jul 5, 2019
    Last edited: Jul 5, 2019
  2. Derk

    Derk 12 year old normie

    Joined:
    Jan 8, 2015
    Messages:
    2,766
    Likes Received:
    1,339
    To answer some of your questions:

    Your if check in your createRootTask() method returns the task when it is not logged in.

    Code (Text):
    1. (p = Players.getLocal()) == null || !p.isVisible())
    1. Local player == null means it's not loaded, in the odd case it is you still want to check if it's visible. I suspect that this will return false when on the lobby screen. You could verify this yourself. Basically inverting this boolean will do the trick.
    2. Second, you should not return null as root task. Your root task should be a branch that checks for logged in and then returns a failure or success task based on that. Keep any logic outside of the main class regarding your tree.
    3. Third, look up the naming conventions in Java/Kotlin. Underscores in variable names are heavily frowned upon.
    4. Fourth, don't delay in your validate() method, you just want a simple boolean that either guides you to the success or failure task. Do any logical operations in the respective LeafTask execute() blocks.
    5. Fifth, you are getting the NullPointerException on the delay because you have not nullchecked 'p'. Invoking .isVisible() on a null 'p' results in this exception. You don't want the delay here anyways, so this won't be a problem anymore. But it is good to keep in mind that you need to nullcheck your instances before invoking functions on them.

    Please correct me where I'm wrong @ any other developer if you find mistakes. :)
     
    TrippyToad likes this.
  3. theSmeg

    Joined:
    Jun 25, 2019
    Messages:
    24
    Likes Received:
    5
    Thanks for the reply. I ended up creating a IsLoggedIn branch task:

    Code (Text):
    1. public class IsLoggedIn extends BranchTask {
    2.  
    3.     private IsInventoryFull isInventoryFull = new IsInventoryFull();
    4.     private WaitUntilLoggedIn waitUntilLoggedIn = new WaitUntilLoggedIn();
    5.  
    6.     Player p;
    7.  
    8.     @Override
    9.     public boolean validate() {
    10.         p = Players.getLocal();
    11.         if (p != null) {
    12.             if (p.isVisible()) {
    13.                 return true;
    14.             }
    15.         }
    16.         return false;
    17.     }
    18.  
    19.     @Override
    20.     public TreeTask failureTask() {
    21.         return waitUntilLoggedIn;
    22.     }
    23.  
    24.     @Override
    25.     public TreeTask successTask() {
    26.         return isInventoryFull;
    27.     }
    28.  
    29. }
    its working well so far. As for the variable names I was going through the java tutorials last night and have started camel casing my vars :)
     
    Derk likes this.

Share This Page

Loading...