You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: tutorials/scripting/gdscript/warnings/ASSERT_ALWAYS_FALSE.rst
+23-11Lines changed: 23 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,27 +10,39 @@ The warning message is:
10
10
When this warning occurs
11
11
------------------------
12
12
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.
14
14
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.
16
16
17
17
.. code-block::
18
18
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")
22
21
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")
25
24
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.
29
41
30
42
How to fix this warning
31
43
-----------------------
32
44
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>`.
0 commit comments