ThePat02 / BehaviourToolkit

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

fix: Static Typing for _get_configuration_warnings #70

Closed dfego closed 6 months ago

dfego commented 6 months ago

I was getting warnings in the editor with scripts derived from the script templates because they didn't specify a return type for the _get_configuration_warnings() function.

That said, this has created four warnings that I cannot understand in VSCode's linting, however that works. So this is theoretically not ready for incorporation without further review.

The errors I'm seeing are all:

The function signature doesn't match the parent. Parent signature is "_get_configuration_warnings() -> Variant".

This makes no sense to me, because if I ctrl-click to the parent, it clearly shows -> PackedStringArray. I'm seeing this for the following files:

The common link here is that these are FSM ones, and the BT ones didn't give me any such issues, but I have no idea if that's relevant.

Also, I have the formatter installed, so various changes to whitespace are a result of that.

ThePat02 commented 6 months ago

Do you also get these warnings in the editor? I'll look into it later today.

dfego commented 6 months ago

The original ones that caused me to report this, yes I originally saw those in the editor. The errors I mentioned seeing after those fixes I somehow didn't see in the editor. Since I thought the editor and code used the same language server, I do find that perplexing.

ThePat02 commented 6 months ago

And you saw the warning when extending these specific classes?

ThePat02 commented 6 months ago

Just checked it out and can't seem to get the Warnings in VSCode. Are you using any specific Linter or just the GDScript language server? I also can't reproduce the original warning message in the editor. How exactly did you get that?

dfego commented 6 months ago

UPDATE, below was original response. I had turned on all the warnings. In Project Settings -> Debug -> GDScript, I have everything turned on, including "Untyped Declaration". So, that's why it's giving me a hard time there. If you turn that on, you'll see it.

Testing now, I'm:

  1. Creating a fresh project
  2. Installing BehaviourToolkit via the AssetLib tab
  3. Enabling plugin
  4. Creating a new 2D Scene
  5. Creating a new BTRoot node
  6. Creating a new BTLeaf
  7. Extend the script for BTLeaf
  8. Starting the scene

And... not seeing the issue I saw. Normally I'd do the above before submitting anything at all, but it seemed like such a logical thing (the warning was valid) that I didn't. The error I get within my other project is:

W 0:00:03:0018   Function "_get_configuration_warnings()" has no static return type.
  <GDScript Error>UNTYPED_DECLARATION
  <GDScript Source>get_next_item_from_list_if_any.gd:18

And that's just on this, which is the default bit of code added by the script template:

# Add custom configuration warnings
# Note: Can be deleted if you don't want to define your own warnings.
func _get_configuration_warnings():
    var warnings: Array = []

    warnings.append_array(super._get_configuration_warnings())

    # Add your own warnings to the array here

    return warnings

I tried to make this easy by just creating a PR rather than submitting a ticket, but I'm not sure what's different in my project and this stripped down sample project that could cause this difference. The only plugins I have are format-on-save, and git (as well as yours).

ThePat02 commented 6 months ago

In Project Settings -> Debug -> GDScript, I have everything turned on, including "Untyped Declaration".

Ah, I see. I am now getting those warnings too. image

The common link here is that these are FSM ones, and the BT ones didn't give me any such issues, but I have no idea if that's relevant.

I figure, the problem is mostly because some of the FSM scripts do not have static return types, where as most BTs use -> PackedStringArray. This is just an inconsistency on my part. I guess the linter uses the overridden method that has an untyped return declaration (equals -> Variant) and starts screaming and kicking.

ThePat02 commented 6 months ago

I cannot get any other warnings. Would you mind uploading a minimal project where you get these other warnings so I can see?

dfego commented 6 months ago

Not seeing those anymore, now that I've closed everything and gone back in fresh. Makes sense I guess, since the warnings weren't making sense anyway.

ThePat02 commented 6 months ago

Not seeing those anymore, now that I've closed everything and gone back in fresh. Makes sense I guess, since the warnings weren't making sense anyway.

Yeah, I found the language server can be a bit of a mess sometimes. Especially when files haven't been loaded in a long time. If you don't have anything to add, I will merge this ASAP! Thank your for contributing <3