Task.current
Task.current is consequence of using methods as task implementations rather than classes. It would have been more tedious to define a new class each time a new task is required. But this construction is indeed a bit exotic if you expect an OOP architecture. Task.current is a key object, I will put more focus on its importance in the documentation or future tutorials. Thanks for your feedback on this important point.
About the syntax
About the syntax, if you have an idea about what would be more appropriate please tell me! And don’t worry about it’s already released; it’s always possible to implement a versioning.
The language is different from existing languages indeed (except for the indentation which is similar to Python). In fact, I’ve started with the idea to define the BT directly in C#, but I couldn’t come up with a satisfying API that would make the BT both simple to write and easy to read. That’s why I went in the direction of defining a new scripting language. A positive byproduct of that solution is the realtime visualization: that would have been impossible or really hard to implement in a C#-only solution.
The basic principles behind the syntax are:
- Everything is a node (tree, sequence, while, fallback, task, …)
- A node can have parameters (which type can be: boolean, int, float or string)
- A node can have other nodes as children.
Following this principle, the condition and the body are indeed both children of the while node, only their order distinct them from each other. The first child is the condition, the second child is the body. However, it’s possible to make a visual distinction between the condition and the body by using indentation or single line parenting.
For example:
// This...
while
condition
body
// ...is the same as
while condition
body
Side note: while is not a loop (in Panda)
I know it sounds confusing, but the while node is not a loop but a conditional node. The only node that implements looping is the repeat node.
Let’s clarify that with examples.
(The syntax highlighting is not meaningful here, it’s just that C# highlighting is applied… I’m dreaming about having a dedicated Panda syntax highlighting, at the forum maintainers)
For example the following construction is not a loop, but it’s rather a condition:
// Start the engine and drive until the tank is empty.
while hasGass
sequence
StartEngine
Drive
The while node is used to run a node under a satisfied assumption. We start the engine only once, then we keep driving while we have gass. There is no repetition.
The equivalent of the while loop of other programming language is implemented with the combination of the while node and the repeat node:
// Shoot at the target several times as long as we have bullets.
while hasBullets
reapeat
sequence
AimAtTarget
Shoot
Here we repeat at aiming and shooting at the target while we have bullets. The aiming and shooting are repeated.
Internals
The script is not parsed as the BT is executed, it’s parsed only once. A tree is indeed constructed as the result of the parsing.
I tried to exposed the minimum of the internal functioning to the user (encapsulation principle). It’s possible to access the internal tree from code, but that’s not documented. Do you think there are use cases to have it exposed through the API, or are you just curious?