discord-rpc-godot
discord-rpc-godot copied to clipboard
Add static typing to all properties
What happened?
I've just enabled enforcing static typing in my project, because I do like to see errors when I miss typing my variables. However, most of the variables in this plugin are completely untyped, so I was left with tens of errors to "fix".
It is a bit tricky to track down the root of these errors since they do come from an addon, so they appear with gdscript://
with a strange ID instead of a traceable res://
path.
I added static typing to every single variable and changed all of the paths to use this format: @onready var name: Type = $Path/To/Node as Type
. It was a bit tedious, and since I do plan to use this addon and future versions in future projects, I would love if the addon could have strict static typing enforced already. plugin.gd
seemed to be the biggest culprit with all of its paths and variables. The things that should be typed are:
- Variable and constant declarations, as
var name: Type
(andas Type
if necessary) - Function return values and parameters, as
func name(parameter: Type) -> Type:
Aside from static typing, unsafe property access should also be fixed (Like setting the position
of a Node
which might be a Node2D
but you don't know if it is).
If you do plan to do this, you can check if it's been done correctly by enabling these settings:
Thanks for reaching the bottom and please ease the suffering of us static typers. :)
Version
1.3.1
Godot Version
4.2.1
Exact steps to reproduce this error
Simply enable these settings and you'll get the same errors each time you reload the project:
GDScript
The whole repo
Godot output
PAIN
Additional information
cough cough
It's dusty down here.
Checks
- [x] I tried reinstalling the addon or tried to fix it myself with other methods.
- [X] I tried restarting Discord and Godot completely.
- [X] I did read the documentation https://vaporvee.com/docs/discord-rpc-godot/
Huh i thought i already did do that but will fix that soon! thanks for reporting :)
"Soon" i said... Will make some time to fix all gh issues and some more next week. I promise
No problemo!
okay i think i fixed it but i didn't get by far as many errors as you. I made everything static i may send you the update early to test it. Also thank you for showing me these settings these are very helpful! I like to type static too but forget it often..
ADDON-Discord-RPC-Godot.zip try it whenever you have time for it
While the RPC is working 100%, the errors still seem to be there. It looks like there are only a few stray untyped variables left.
Checking the changes in github, and it looks to be a script in Debug.tscn:
The red is my version, which was static-typing-error-free.
weird i dont get these errors somehow but will fix them