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

Documentation is not clear on Conditional aborts #10

Open
acdamiani opened this issue Jan 18, 2024 · 1 comment
Open

Documentation is not clear on Conditional aborts #10

acdamiani opened this issue Jan 18, 2024 · 1 comment
Labels
documentation Improvements or additions to documentation

Comments

@acdamiani
Copy link
Owner

The documentation currently only addresses Conditional aborts in passing. It would be worth it to expound upon what they are and how they work, since they are pretty important for any mildly complex behavior tree.

@acdamiani acdamiani added the documentation Improvements or additions to documentation label Jan 18, 2024
@ijisthee
Copy link

Ohhh my... Today I've had a hard nut to crack. Haha.

Have a look at this code (https://github.com/acdamiani/schema/blob/main/Runtime/Proc/ExecutableNode.cs#L178):

bool isSub = current.IsSubTreeOf(node);
bool isPriority = current.IsLowerPriority(node);

switch (c.abortsType)
{
    case Conditional.AbortsType.Self when !isSub:
    case Conditional.AbortsType.LowerPriority when !isPriority:
    case Conditional.AbortsType.Both when !isPriority && !isSub:
        continue;
}

bool status = c.Evaluate(conditionalMemory[id][j], context.agent);
status = c.invert ? !status : status;

if (!lastConditionalStatus.TryGetValue(j, out bool last)) last = status;
lastConditionalStatus[j] = status;

if (last == status) continue;

switch (c.abortsWhen)
{
    case Conditional.AbortsWhen.OnSuccess when status:
    case Conditional.AbortsWhen.OnFailure when !status:
    case Conditional.AbortsWhen.Both:
        return true;
}

These kind of double negations is not made for a human brain. :)

For instance:

I have a class that returns true if the enemy has Mana to fight.
I want him to chase the player if there is no mana but abort the node if mana is back.

Sounds easy but the settings creates a knot in a humans head. Haha.

If you would create an if statement it would look like this:

if (!HasMana()) {
	ChasePlayer();
} else if (AbortType == AbortType.Self && HasMana()) {
	StopChasePlayer
}

image

I've create my own text for this Conditional to make it more clear.
Maybe you could also do that by default? I know it's not easy because of the different wordings. Believe me, in German it would be hell on earth to standardize that. Haha.

image

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

No branches or pull requests

2 participants