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.
Zakłada, że [param condition] jest [code]prawdziwe[/code]. Jeśli [param condition] jest [code]fałszywe[/code], zostaje wywołany wyjątek. Podczas działania w edytorze zostanie także wstrzymana praca kodu do wznowienia przez programistę. Może być użyte jako mocniejsza forma [method @GlobalScope.push_error] do raportowania błędów dla programistów lub użytkowników wtyczek. Opcjonalna [param message] może zostać pokazana w połączeniu do ogólnej wiadomości "Assertion failed". Można użyć ją do podania szczegółów dlaczego asercja zawiodła. [b]Ostrzeżenie:[/b] Ze względu na wydajność, kot który wykonuje się wewnątrz [method assert] zostaje wywołany wyłącznie wewnątrz debugowego builda lub wewnątrz edytoru kodu. Nie zawieraj wewnątrz warunku kod który posiada efekty uboczne. W przeciwnym wypadku skutkuje to innych zachowaniem w kodzie dla projektu eksportowanego w trybie release. [codeblock] # wyobraź sobie że potrzebujemy prędkości która występuje tylko w zakresie od 0 do 20. var speed = -10 assert(speed < 20) # Prawda, program kontynuuje. assert(speed >= 0) # Fałsz, program zatrzymuje się. assert(speed >= 0 and speed < 20) # Możesz połączyć oba wyrażenia w jeden warunek. assert(speed < 20, "ograniczenie prędkości wynosi 20") # Pokaż wiadomość. [/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.
Opcjonalna [param message] może zostać pokazana w połączeniu do ogólnej wiadomości "Assertion failed". Można użyć ją do podania szczegółów dlaczego asercja zawiodła.
[b]Ostrzeżenie:[/b] Ze względu na wydajność, kot który wykonuje się wewnątrz [method assert] zostaje wywołany wyłącznie wewnątrz debugowego builda lub wewnątrz edytoru kodu. Nie zawieraj wewnątrz warunku kod który posiada efekty uboczne. W przeciwnym wypadku skutkuje to innych zachowaniem w kodzie dla projektu eksportowanego w trybie release.
[codeblock]
# wyobraź sobie że potrzebujemy prędkości która występuje tylko w zakresie od 0 do 20.
var speed = -10
assert(speed < 20) # Prawda, program kontynuuje.
assert(speed >= 0) # Fałsz, program zatrzymuje się.
assert(speed >= 0 and speed < 20) # Możesz połączyć oba wyrażenia w jeden warunek.
assert(speed < 20, "ograniczenie prędkości wynosi 20") # Pokaż wiadomość.
[/codeblock]