Asserts that the [param condition] is [code]true[/code]. If the [param condition] is [code]false[/code], an error is generated. When running from the editor, the running project will also be paused until you resume it. This can be used as a stronger form of [method @GlobalScope.push_error] for reporting errors to project developers or add-on users. An optional [param message] can be shown in addition to the generic "Assertion failed" message. You can use this to provide additional details about why the assertion failed. [b]Warning:[/b] For performance reasons, the code inside [method assert] is only executed in debug builds or when running the project from the editor. Don't include code that has side effects in an [method assert] call. Otherwise, the project will behave differently when exported in release mode. [codeblock] # Imagine we always want speed to be between 0 and 20. var speed = -10 assert(speed < 20) # True, the program will continue. assert(speed >= 0) # False, the program will stop. assert(speed >= 0 and speed < 20) # You can also combine the two conditional statements in one check. assert(speed < 20, "the speed limit is 20") # Show a message. [/codeblock] [b]Note:[/b] [method assert] is a keyword, not a function. So you cannot access it as a [Callable] or use it inside expressions.
Перевіряє чи [param condition] є [code]true[/code]. Якщо [param condition] є [code]false[/code], то генерується помилка. При запуску з редактора, запущений проект буде призупинено, поки ви не відновите його. Це можна використовувати як посилену форму [method @GlobalScope.push_error] для повідомлень про помилки розробникам проекту або користувачам доповнень. Додаткове [param message] може бути додане до згенерованого повідомлення "Умова не виконана". Ви можете використовувати його для надання додаткових відомостей про те, чому не вдалося виконати умову. [b]Попередження:[/b] З міркувань безпеки, код всередині [method assert] виконується лише у налагоджувальних збірках або під час запуску проекту з редактора. Не включайте до виклику. Не включайте код, що містить побічні ефекти до виклику [method assert]. В іншому випадку проект буде вести себе по-іншому при експорті в режимі випуску. [codeblock] # Уявімо, що ми хочемо, щоб швидкість завжди була в між 0 і 20. var speed = -10 assert(speed < 20) # True, програма продовжить роботу. assert(speed >= 0) # False, програма зупиниться. assert(speed >= 0 and speed < 20) # Ви можете також поєднати два умовні оператори в одній перевірці. assert(speed < 20, "обмеження швидкості - 20") # Показати повідомлення. [/codeblock]
An optional [param message] can be shown in addition to the generic "Assertion failed" message. You can use this to provide additional details about why the assertion failed.
[b]Warning:[/b] For performance reasons, the code inside [method assert] is only executed in debug builds or when running the project from the editor. Don't include code that has side effects in an [method assert] call. Otherwise, the project will behave differently when exported in release mode.
[codeblock]
# Imagine we always want speed to be between 0 and 20.
var speed = -10
assert(speed < 20) # True, the program will continue.
assert(speed >= 0) # False, the program will stop.
assert(speed >= 0 and speed < 20) # You can also combine the two conditional statements in one check.
assert(speed < 20, "the speed limit is 20") # Show a message.
[/codeblock]
[b]Note:[/b] [method assert] is a keyword, not a function. So you cannot access it as a [Callable] or use it inside expressions.
Додаткове [param message] може бути додане до згенерованого повідомлення "Умова не виконана". Ви можете використовувати його для надання додаткових відомостей про те, чому не вдалося виконати умову.
[b]Попередження:[/b] З міркувань безпеки, код всередині [method assert] виконується лише у налагоджувальних збірках або під час запуску проекту з редактора. Не включайте до виклику. Не включайте код, що містить побічні ефекти до виклику [method assert]. В іншому випадку проект буде вести себе по-іншому при експорті в режимі випуску.
[codeblock]
# Уявімо, що ми хочемо, щоб швидкість завжди була в між 0 і 20.
var speed = -10
assert(speed < 20) # True, програма продовжить роботу.
assert(speed >= 0) # False, програма зупиниться.
assert(speed >= 0 and speed < 20) # Ви можете також поєднати два умовні оператори в одній перевірці.
assert(speed < 20, "обмеження швидкості - 20") # Показати повідомлення.
[/codeblock]