BehaviorTree DSL #495
-
Hi, this is related to a previous discussion. @deviodesign might have some input because I think he wrote the extensions initially? I have a tree like below, which seems to work just fine. However, I don't really like the guard syntax and maybe I am missing something? I'd prefer to write something like because as of now I have a mixture of DSL functions and constructor calls: selector {
sequence{
guardSequence{
random(ConstantFloatDistribution(offensiveMagicChange))
HasOffensiveMagic()
}
// ...
}
} Is this somehow possible with the existing DSL? If so, how do I achieve that? fun defaultBehavior(
world: World,
entity: Entity,
offensiveMagicChange: Float = 0.2f,
defensiveMagicChange: Float = 0.2f,
): BehaviorTree<Entity> = behaviorTree {
`object` = entity
selector {
sequence {
guard = GdxAiSequence(
GdxAiRandom(ConstantFloatDistribution(offensiveMagicChange)),
HasOffensiveMagic(world)
)
useOffensiveMagic(world)
}
sequence {
guard = GdxAiSequence(
GdxAiRandom(ConstantFloatDistribution(defensiveMagicChange)),
HasDefensiveMagic(world)
)
useDefensiveMagic(world)
}
sequence {
guard = GdxAiSequence(HasAttack(world))
useAttack(world)
}
useNothing(world)
}
}
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
@deviodesign is the best person to ask, I only reviewed that module. That being said, it's certainly possible to replace any class with a DSL. In order to replace something like
|
Beta Was this translation helpful? Give feedback.
-
It's been a while since I used this. If I understand it correctly, you want to guard against using offensive magic if the entity has no offensive magic capabilities for example. A sequence fails as soon as one of its children fails, so you could create your own task which acts as a guard like so: sequence {
checkOffensiveMagicTask(world)
useOffensiveMagic(world)
} Another option would be that useOffensiveMagic could fail if its conditions aren't met. |
Beta Was this translation helpful? Give feedback.
-
Ah okay, that is an interesting piece of information thank you! That will solve my issue. One last thing: why are the DSL methods returning Ints instead of the real object? Most likely this is necessary due to how the DSL works? But imo would be more intuitive if sequence e.g. returns a sequence object instead of an int. |
Beta Was this translation helpful? Give feedback.
It's been a while since I used this. If I understand it correctly, you want to guard against using offensive magic if the entity has no offensive magic capabilities for example.
A sequence fails as soon as one of its children fails, so you could create your own task which acts as a guard like so:
Another option would be that useOffensiveMagic could fail if its conditions aren't met.
Otherwise there's no guard task in gdx ai as far as I know.