GDScript 警告系统
GDScript 警告系统是对静态类型的补充(也可以在没有静态类型的情况下工作),可以在开发过程中帮助避免因难以发现的错误而导致运行时错误。
可以在项目设置的 GDScript 部分配置警告:

备注
要在侧边栏中看到 GDScript 部分的设置,必须启用 高级设置 选项;如果该选项未开启,也可以搜索 "GDScript" 来进行查找。
可以在脚本编辑器的状态栏中找到当前 GDScript 文件的警告列表。下例中有 2 个警告:

To ignore single warnings within a file, use the @warning_ignore annotation. You can click on the ignore link to the left of the warning's description. Godot will add an annotation above the corresponding line and the code won't trigger the corresponding warning anymore:

To ignore multiple warnings in a region within a file, use the
@warning_ignore_start
and @warning_ignore_restore
annotations. You can omit @warning_ignore_restore
if you want to ignore
the specified warning types until the end of the file.
警告不会阻止游戏的运行,但是你可以根据需要将其转换为错误,除非你修复所有警告,否则游戏无法编译。前往项目设置的 GDScript
部分打开此选项。这是与前一个示例相同的文件,在启用了警告转成错误这个设置之后:
