Skip to content

Commit 1d179a1

Browse files
committed
Improve documentation for ASSERT_ALWAYS_FALSE
1 parent d0bdcc7 commit 1d179a1

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

tutorials/scripting/gdscript/warnings/ASSERT_ALWAYS_FALSE.rst

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,39 @@ The warning message is:
1010
When this warning occurs
1111
------------------------
1212

13-
The :ref:`assert() <class_@GDScript_method_assert>` keyword can be used to ensure that a given condition is met before allowing code execution to continue. If the first argument passed to it evaluates to ``true``, the rest of the function will run as expected; if it is ``false``, then the project will stop.
13+
The :ref:`assert() <class_@GDScript_method_assert>` keyword can be used to ensure that a given condition is met before allowing code execution to continue. If the first argument passed to it is truthy, the rest of the function will run as expected; if it is falsy, then the project will stop.
1414

15-
If ``assert()`` is passed an expression that is guaranteed to be ``false``, then the ``assert()`` call will always stop the project.
15+
If ``assert()`` is passed something guaranteed to be falsy, then the ``assert()`` call will always stop the project.
1616

1717
.. code-block::
1818
19-
# The boolean false will always be false, so this assert will always stop
20-
# the program.
21-
assert(false, "False is false")
19+
# Zero always evaluates to false.
20+
assert(0, "Zero is falsy")
2221
23-
# Likewise, 5 will never be 6, so this assert will always stop the program.
24-
assert(5 == 6, "5 isn't equal to 6")
22+
# Likewise, an empty string always evaluates to false.
23+
assert("", "An empty string is falsy")
2524
26-
# This line of code won't be executed in debug builds because the editor
27-
# will have stopped at the assert calls above.
28-
print("Hello, world!")
25+
.. note::
26+
27+
Godot will *not* raise this warning if a literal falsy boolean is passed:
28+
29+
.. code-block::
30+
31+
# Despite false being passed, this won't raise ASSERT_ALWAYS_FALSE.
32+
assert(false, "False is false")
33+
34+
# This evaluates to a boolean which is false, so it also won't raise
35+
# the warning.
36+
assert(3 == 4, "3 isn't equal to 4")
37+
38+
This is because ``assert(false)`` calls are often used in development to forcibly halt program execution and avoid strange errors later on.
39+
40+
See `issue #58087 <https://github.com/godotengine/godot/issues/58087>`_ for more information.
2941

3042
How to fix this warning
3143
-----------------------
3244

33-
Assuming you want code following the ``assert()`` to run, remove it from your code. If you do want code execution to stop at that point, :ref:`consider using breakpoints instead <doc_debugger_tools_and_options>`.
45+
Assuming you want code following the ``assert()`` to run, remove it from your code. If you do want code execution to stop at that point, replace the condition with ``false``, or :ref:`consider using breakpoints instead <doc_debugger_tools_and_options>`.
3446

3547

3648

0 commit comments

Comments
 (0)