Giter Club home page Giter Club logo

Comments (3)

meniku avatar meniku commented on July 23, 2024

Yes you're right. The idea behind the ON_CHANGE is not really clear from it's name.

The idea was to have no condition on the value itself (that's why it's always true), but rather have the possibility to re-evaluate the "stops condition" whenever the value in the blackboard changed. I think this was useful to me to be sure a specific subranch is always re-executed on a value change, regardless of it's contents. For a loop by that would also execute like you pointed out.

The thing you want to achieve would require the decorator to remember the last known value of the blackboard and then compare this on execution. I can add such a decorator this evening (or at least post you some code here) if you like.

I will defiantly rename the Operator.ON_CHANGE operator to something like Operator.ALWAYS_TRUE, as it's indeed confusing right now.

from npbehave.

meniku avatar meniku commented on July 23, 2024

You could create your own new node type that does track for changes on a blackboard key. Something like that should work for you:

using NPBehave;

public class BlackboardValueChanged : Decorator
{
    private object lastValue;
    private string blackboardKey;

    public BlackboardValueChanged(string blackboardKey, Node decoratee) : base("BlackboardValueChanged", decoratee)
    {
        this.lastValue = null;
        this.blackboardKey = blackboardKey;
    }

    protected override void DoStart()
    {
        object newValue = RootNode.Blackboard.Get(blackboardKey);
        if (lastValue != newValue)
        {
            lastValue = newValue;
            Decoratee.Start();
        }
        else
        {
            Stopped(false);
        }
    }

    override protected void DoStop()
    {
        Decoratee.Stop();
    }

    protected override void DoChildStopped(Node child, bool result)
    {
        Stopped(result);
    }
}

I didn't test it, but I think you should be able to adjust it for your needs.

from npbehave.

MohHeader avatar MohHeader commented on July 23, 2024

Aha Ok,

I got it now, only naming thing,,
No worries,

And thanks for the "BlackboardValueChanged" code.
👍

from npbehave.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.