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

Suggestion: replace int with strongly-typed enum BTTickResult where relevant #33

Open
hsandt opened this issue Mar 18, 2023 · 2 comments
Labels
breaking compatibility enhancement New feature or request question Further information is requested

Comments

@hsandt
Copy link

hsandt commented Mar 18, 2023

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.

@Earewien
Copy link
Owner

@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

image

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 ?

@Earewien Earewien added the question Further information is requested label Mar 19, 2023
@hsandt
Copy link
Author

hsandt commented Mar 22, 2023

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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking compatibility enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants