ThePat02 / BehaviourToolkit

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

Example Scene to use static typing #54

Closed TheYellowArchitect closed 9 months ago

TheYellowArchitect commented 9 months ago

I know there will be a new example scene in the future, but I was curious of the setup of current version. It's kinda hard to read for a first-time user (since all nodes have a script attached, even though the script has no logic), but what I want to mention in this issue is that there are function calls which do not point anywhere and are dynamically cast.

On the FSMState "TransformIntoGhost" there is the code

func _on_enter(actor: Node, _blackboard: Blackboard):
    # Make Transparent
    actor.set_modulate(Color(1, 1, 1, 0.5))
    actor.ghost_state_machine.fire_event("fully_transformed")

I cannot ctrl+click set_modulate either.

func _on_enter(actor: Node, _blackboard: Blackboard):
    # Make Transparent
    (actor as Actor).set_modulate(Color(1, 1, 1, 0.5))
    (actor as Actor).ghost_state_machine.fire_event("fully_transformed")

The above is more intuitive imo, and its a codestyle I suggest for the future example scene. After all, the example scene is what convinces a developer whether to use or not

ThePat02 commented 9 months ago

It's kinda hard to read for a first-time user

Yes, I totally agree, that that the current example scene needs some work. It functions as some crude kind of testing and regression-catching device, as it uses most of the new nodes. I am hoping to get some simpler examples in for the next big release.

[...] but what I want to mention in this issue is that there are function calls which do not point anywhere and are dynamically cast. [...] I cannot ctrl+click set_modulate either.

This is a good point, however I think using something like (actor as Actor) can become really tiresome and exhausting to write and read. What do you think of something like this?

## Executes after the state is entered.
func _on_enter(actor: Node, _blackboard: Blackboard):
    # Cast to Actor
    actor = actor as Actor

    # Make Transparent
    actor.set_modulate(Color(1, 1, 1, 0.5))
    actor.ghost_state_machine.fire_event("fully_transformed")
TheYellowArchitect commented 9 months ago

definitely cleaner, I feel dumb for not having thought of it hahaha

ThePat02 commented 9 months ago

definitely cleaner, I feel dumb for not having thought of it hahaha

I will close this issue for now, even tho I won't update the current example scene, as there already is a new one on the way (#55). You are VERY WELCOME to contribute your own examples to the 2.0.0 branch if you find that your testing could help others understand the plugin in a better way!