ThePat02 / BehaviourToolkit

A collection of tools for AI Behaviour in the Godot 4 Game Engine!
MIT License
368 stars 15 forks source link

Loop decorator leaf #53

Closed evilenzo closed 9 months ago

evilenzo commented 9 months ago

Title speaks for itself. It's kinda hard to make loops rn. I know that classic BT doesn't have this but such feature seems reasonable

ThePat02 commented 9 months ago

Well there is the "Repeater" decorator. What kind of functionality are you missing exactly?

evilenzo commented 9 months ago

Conditions would be great. I think it should have opportunity to use custom script

evilenzo commented 9 months ago

Also as I can see it applies only for one leaf and what if I want to repeat some leaves sequence?

ThePat02 commented 9 months ago

Conditions would be great. I think it should have opportunity to use custom script

I will look into it.

I think you could use sequences to have more leaves looping.

evilenzo commented 9 months ago

I think I understood your idea so the issue can be closed

evilenzo commented 9 months ago

This is my fault I don't understand flow correctly. I just had signaling exit node in the end of sequence so sequence worked exactly one time. Without it sequence will loop like I expect

evilenzo commented 9 months ago

But wait. What if I want a sequence that executes every leaf exactly once with such logic:

  1. Fail if any of leaves fail
  2. Succes if ALL of leaves success
  3. Go to next leaf if it is RUNNING
evilenzo commented 9 months ago

Oh well, I checked sequence logic but let me check again...

evilenzo commented 9 months ago

It seems like SimpleParallel does what I want but the naming can be misleading. It is not actually parallel

ThePat02 commented 9 months ago

But wait. What if I want a sequence that executes every leaf exactly once with such logic:

  1. Fail if any of leaves fail
  2. Succes if ALL of leaves success
  3. Go to next leaf if it is RUNNING

Oh yes, Simple Parallel is exactly what you want. The naming can be somewhat misleading, indeed! The node is somewhat unstable #38 and I am not sure if all policies work correctly right now. If you encounter any problems, make sure to report the bug on #38 and/or dive in the code and try to fix it yourself. Didn't have time to implement proper unit testing (yet)

evilenzo commented 9 months ago

Everything works ok but we probably should rename it to something more clear

evilenzo commented 9 months ago

Because it looks like it is more a loop node instead of parallel

ThePat02 commented 9 months ago

Everything works ok but we probably should rename it to something more clear

I didn't come up with this name! It is a standardized name for this type of composite (as seen in Unreal Engine for example) and if you think about it, all leaves are executed "side by side" before this node returns a value. A Sequence performs them after each other. (Well a Parallel technically does that too, but you get the concept)