What's new
  • Visit Rebornbuddy
  • Visit Panda Profiles
  • Visit LLamamMagic
  • Visit Resources
  • Visit Downloads
  • Visit Portal

Initializing new Behavior Tree?

strix

New Member
Joined
Feb 13, 2010
Messages
442
Reaction score
18
Is it possible and how to initialize new BT inside standard Pulse?

I would love to write my plugin in TreeSharp rather than normal code.
 
If using visual studio do a search "addchild" or something of that sort.
I saw something like that in TreeRoot or something.
Can't remember offhand.

This could make it a pain to create, but could also be a new way of doing things with plugins.

Good Luck,
Panda.
 
Hmmmm, I am interested in this answer as well .... I don't see why you couldn't create a Composite in your Pulse, and just let it run through .... tho don't take my word for it ....


Random Freehand:
Code:
        private TreeSharp.Composite DoSomething()
        {
            return new PrioritySelector(
                new Decorator(ret => _me.IsAlive,
                    new Action(o => Lua.DoString("EatMe();"))));
        }
        public override void Pulse()
        {
            DoSomething();
        }
 
Last edited:
Lol always with the EatMe()
Must be some buff food or something.
 
I am going more and more insane with each minute on my current deployment.

Public int Insanity;

Public void SanityTest()
{
Insanity = ((DateTime.Now - _DeploymentStartTime).TotalMinutes * 2) * 2);
if(Insanity > 1) Log("You are officially Fucking Crazy.");
}

As you can image... I've been officially insane for a long time now.
 
You can't simply run it :P

I got to this:
PHP:
private object ctx;
private bool flag = true;

public override void OnButtonPress()
{
    flag = true;
}

Composite _root;
private Composite Root
{ 
    get
    {
        return _root ?? (_root = CreateABHelperBehavior());
    }
}

private Composite CreateABHelperBehavior()
{
    return new PrioritySelector(
        new Action(ret => {
            Logging.Write("It's working!!!!");
            flag = false;
            return RunStatus.Success;
        })
    );
}

public override void Initialize()
{
    ctx = new object();
    flag = true;
    Root.Start(ctx);
}

public override void Pulse()
{
    while(flag)
    {
        Root.Tick(ctx);
    }
}

But it is running just once (i use plugin button to set flag to true).
For second time the while(flag) loop is just disabling bot (as it's supposed to when BT doesnt run).

Any ideas?
 
In the composite you are setting
Flag = false;
Which I assume you meant to do.

For the onbuttonpress
If(Flag) flag = false;
Else flag = true;

That way it's a toggle button :)
 
i don't want to toggle it with button, i want to set flag to true
Only my behavior and nothing else is supposed to set flag to false, so when it runs it will exit loop and when it doesn't run the loop will visibly lock HB.
 
Close strix.

Code:
        void PulseTree()        {
            // Assume root.Start(null) was called somewhere during init
            while (flag)
            {
                try
                {
                    root.Tick(null);
                    if (root.LastStatus != RunStatus.Running)
                    {
                        root.Stop(null);
                        root.Start(null);
                    }
                }
                catch (ThreadAbortException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    Logging.Write(ex.ToString());
                    root.Stop(null);
                    root.Start(null);
                }
            }
        }

I really need to create a "CompositeExecutor" or something.
 
So i actually need to Stop and then Start before each Tick?

I thought you need to Start it before first and Stop after last usage ;)
 
Last edited:
So i actually need to Stop and then Start before each Tick?

Yes. But only if the RunStatus isn't "Running".

Admittedly, the API is slightly confusing if you don't know whats actually going on in the methods themselves.

Stop cleans up children and any state stuff.
Start sets up disposers, gets children ready, etc.
 
PHP:
using System;
using System.Threading;
using System.Windows.Forms;
using TreeSharp;

namespace strix
{
    class TreeSharpRoot
    {
        private Composite _root;

        public TreeSharpRoot(Composite newRoot) 
        {
             _root = newRoot;
            _root.Start(null);
        }

        public void PulseTree()
        {
            // Assume root.Start(null) was called somewhere during init
            try
            {
                _root.Tick(null);
                if(_root.LastStatus != RunStatus.Running)
                {
                    _root.Stop(null);
                    _root.Start(null);
                }
            }
            catch(ThreadAbortException)
            {
                throw;
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.ToString());
                _root.Stop(null);
                _root.Start(null);
            }
        }
    }
}
PHP:
static TreeSharpRoot btroot1 = new TreeSharpRoot( new ActionAlwaysSucceed( ) );
public override void Pulse()
{
    btroot1.PulseTree();
}

Enjoy :)
 
Last edited:
Back
Top