Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nested if/then/else rules #3

Open
mirkopeloso opened this issue Jul 11, 2024 · 1 comment
Open

nested if/then/else rules #3

mirkopeloso opened this issue Jul 11, 2024 · 1 comment

Comments

@mirkopeloso
Copy link

Hi,
seems that Sutra is unable to process nested rule functions, here an example:


import { Sutra } from '@yantra-core/sutra';

// creates a new sutra instance
const s = new Sutra();

s.addCondition('gt 0', (e) => e > 0);
s.addCondition('gt 10', (e) => e > 10);
s.addCondition('gt 20', (e) => e > 20);

s
    .if('gt 0')
    .then(rules =>
        rules
            .if('gt 20')
            .then('ok greater then 20')
            .else(
                rules => rules
                    .if('gt 10')
                    .then('OK greater than 10')
                    .else('KO lower than 10')
            )

    ).else('KO lower than 0');



s.onAny((ev, data, node) => {
    console.log('onAny', ev);
});

s.tick(1);
s.tick(14);
s.tick(-5);

OUTPUT:

onAny [Function (anonymous)]
onAny [Function (anonymous)]
onAny KO lower than 0

It's my fault constructing behavior tree or it's a bug?

Thank you so much

@Marak
Copy link
Contributor

Marak commented Sep 11, 2024

I'm not sure. There are lots of passing tests for nested. If you can check in a failing test we could look at it.

I would recommend looking at the tests for usage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants