warning_system.rst 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. .. _doc_gdscript_warning_system:
  2. GDScript warning system
  3. =======================
  4. The GDScript warning system complements :ref:`static typing <doc_gdscript_static_typing>`
  5. (but it can work without static typing too). It's here to help you avoid
  6. mistakes that are hard to spot during development, and that may lead
  7. to runtime errors.
  8. You can configure warnings in the Project Settings under the section
  9. called **GDScript**:
  10. .. image:: img/typed_gdscript_warning_system_settings.webp
  11. .. note::
  12. You must enable **Advanced Settings** in order to see the
  13. GDScript section in the sidebar. You can also search for "GDScript" when
  14. Advanced Settings is off.
  15. You can find a list of warnings for the active GDScript file in the
  16. script editor's status bar. The example below has 2 warnings:
  17. .. image:: img/typed_gdscript_warning_example.webp
  18. To ignore single warnings within a file, use the
  19. :ref:`@warning_ignore <class_@GDScript_annotation_@warning_ignore>` annotation.
  20. You can click on the ignore link to the left of the warning's description.
  21. Godot will add an annotation above the corresponding line and the code
  22. won't trigger the corresponding warning anymore:
  23. .. image:: img/typed_gdscript_warning_system_ignore.webp
  24. To ignore multiple warnings in a region within a file, use the
  25. :ref:`@warning_ignore_start <class_@GDScript_annotation_@warning_ignore_start>`
  26. and :ref:`@warning_ignore_restore <class_@GDScript_annotation_@warning_ignore_restore>`
  27. annotations. You can omit ``@warning_ignore_restore`` if you want to ignore
  28. the specified warning types until the end of the file.
  29. Warnings won't prevent the game from running, but you can turn them into
  30. errors if you'd like. This way your game won't compile unless you fix
  31. all warnings. Head to the ``GDScript`` section of the Project Settings to
  32. turn on this option to the warning that you want. Here's the same file as
  33. the previous example with the warning ``unused_variable`` as an error turned on:
  34. .. image:: img/typed_gdscript_warning_system_errors.webp