What does the assert() function do?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Ceilingdoor
:warning: Old Version Published before Godot 3 was released.

I saw it in the HTTP class usage example and got a bit confused:

assert( err == OK ) # Make sure all is OK

So, does it simply checks if a statement is true or there’s some deeper meaning?

Also see Does GDScript have an assert command? - Archive - Godot Forum .

Bojidar Marinov | 2016-02-24 15:48

:bust_in_silhouette: Reply From: Mohammad Hadi Aliakb

This means if error is not OK terminate the program.
assert means check if the condition is false then just terminate the program.

I would specify that it only checks the condition in debug mode. Also the program does not terminate, but prints an script error: “Assertion failed.”
If running from the editor, the debugger will catch this error.

neikeq | 2016-02-24 19:27