Skip to content

Commit d0bdcc7

Browse files
committed
Wrote for ASSERT_ALWAYS_FALSE and ASSERT_ALWAYS_TRUE`
1 parent 524ab62 commit d0bdcc7

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

tutorials/scripting/gdscript/warnings/ASSERT_ALWAYS_FALSE.rst

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

13-
TODO
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.
1414

15+
If ``assert()`` is passed an expression that is guaranteed to be ``false``, then the ``assert()`` call will always stop the project.
16+
17+
.. code-block::
18+
19+
# The boolean false will always be false, so this assert will always stop
20+
# the program.
21+
assert(false, "False is false")
22+
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")
25+
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!")
1529
1630
How to fix this warning
1731
-----------------------
1832

19-
TODO
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>`.
2034

2135

2236

tutorials/scripting/gdscript/warnings/ASSERT_ALWAYS_TRUE.rst

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,24 @@ The warning message is:
1010
When this warning occurs
1111
------------------------
1212

13-
TODO
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.
1414

15+
If ``assert()`` is passed an expression that is guaranteed to be ``true``, then the ``assert()`` call will never stop the project, thus making it redundant.
16+
17+
.. code-block::
18+
19+
# The boolean true will always be true, so this assert will never stop
20+
# the program.
21+
assert(true, "True is false, somehow?")
22+
23+
# Likewise, 3 will never be equal to 4, so this assert will never stop
24+
# the program.
25+
assert(3 != 4, "3 is equal to 4")
1526
1627
How to fix this warning
1728
-----------------------
1829

19-
TODO
30+
Remove the ``assert()`` statement from your code.
2031

2132

2233

0 commit comments

Comments
 (0)