godot-yet-another-behavior-tree
godot-yet-another-behavior-tree copied to clipboard
Suggestion: replace int with strongly-typed enum BTTickResult where relevant
I noticed that whenever a BTTickResult is expected, int is used instead as in Godot 3, but it makes it harder to understand code intention and ensure type safety. So it would be better to use enum type BTTickResult instead.
It may break compatibility with existing code though. For instance, BTActionCallable.tick would not be able to accept functions returning int.
However, if all users were meaning to manipulating enum BTTickResult anyway, they will just have to upgrade their code to change int to BTTickResult.
@hsandt It would be a breaking change, so it can be expected in a 4.0 version of the addon.
Perhaps I miss something here, but BTTickResult can not be used as this if we want to strongly type tick methods:
func tick(actor:Node, blackboard:BTBlackboard) -> BTTickResult:
return BTTickResult.SUCCESS
produces error
But if i named the enum inside BTTickResult, it can work
class_name BTTickResult
enum BTResult {
SUCCESS = 0,
RUNNING = 1,
FAILURE = 2
}
...
func tick(actor:Node, blackboard:BTBlackboard) -> BTTickResult.BTResult:
return BTTickResult.BTResult.SUCCESS
Is that whar you are talking about ?
Ah, right, I remember now. I also put my enums under some Enums file/class and I need to write "Enum.MyEnum/ENUM_VALUE" each time. It's the same in C# where you cannot have a wild enum, although you can at least use using to avoid prefixing with a class/namespace each time.
So yes, it would look like this. The only shortcut we can take is BTTickResult.BTResult.SUCCESS -> BTTickResult.SUCCESS (skipping enum name). I don't have a better idea at the moment...