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

Question Best way to share variables among tasks (TaskBot)?

Discussion in 'Developer Support' started by Rambo501, Jan 12, 2019.

  1. Rambo501

    Joined:
    Dec 24, 2018
    Messages:
    28
    Likes Received:
    2
    What would be the best way to share variables among tasks using TaskBot?

    For example when interacting with an npc or object, I'd like to turn "moving the camera" and "walking" into separate tasks, so the target entity has to be shared among these tasks.

    Is there a proper way to do this or should these activities not be in different task classes?
     
  2. ricespud

    Joined:
    Oct 23, 2015
    Messages:
    117
    Likes Received:
    39
    I don't use TaskBot but can't you use getter/setters?
     
  3. Rambo501

    Joined:
    Dec 24, 2018
    Messages:
    28
    Likes Received:
    2
    I mean I can hack it with static variables obviously but I was kinda looking for the proper way to do it, or if I shouldn't be splitting it up if I need shared variables.
     
  4. CuppaJava

    CuppaJava cuppa.drink(java);

    Joined:
    Mar 13, 2018
    Messages:
    6,173
    Likes Received:
    1,387
    By my understanding you shouldn't use static variables since they're shared by the entire bot, every tab. That could be wrong though.

    I've never used TaskBot, and I'm not 100% understanding what you're trying to accomplish, but if you want to make variables available to your whole bot you should create variables in your root bot object that can be called like

    (In your RotateCamera task)
    Npc target = ((MyFightingBot) Environment.getBot()).target;

    And set in a similar way.

    Or use getters and setters, obviously.
     
    Rambo501 likes this.
  5. Rambo501

    Joined:
    Dec 24, 2018
    Messages:
    28
    Likes Received:
    2
    Yeah thanks, I accomplished it using the root bot object. :)

    Just wondering, if you're not using TaskBot, what are you using then? LoopingBot?
     
  6. CuppaJava

    CuppaJava cuppa.drink(java);

    Joined:
    Mar 13, 2018
    Messages:
    6,173
    Likes Received:
    1,387
    I've only ever used TreeBot (and LoopingBot originally).
     
    Rambo501 likes this.
  7. Rambo501

    Joined:
    Dec 24, 2018
    Messages:
    28
    Likes Received:
    2
    That's cool, I honestly didn't even know about TreeBot lol, it looks really convenient.

    Is TreeBot the way to go then?
     
  8. CuppaJava

    CuppaJava cuppa.drink(java);

    Joined:
    Mar 13, 2018
    Messages:
    6,173
    Likes Received:
    1,387
    I'm a fan of it, I find it really helps with structuring the logic of a bot, once you get the hang of it. There's also a tool somewhere on the site that will help generate the skeleton of a TreeBot if you want that. Also you'll want to write out on paper what your bot tree will look like first so you can run through it and make sure your logic will do what you expect.

    But yeah, I recommend at least trying it.
     
    Rambo501 likes this.
  9. Rambo501

    Joined:
    Dec 24, 2018
    Messages:
    28
    Likes Received:
    2
    Definitely gonna try it next time! I've seen some examples and I can definitely see the appeal.
     

Share This Page

Loading...