Asserts that the [code]condition[/code] is [code]true[/code]. If the [code]condition[/code] 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 push_error] for reporting errors to project developers or add-on users. [b]Note:[/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. The optional [code]message[/code] argument, if given, is shown in addition to the generic "Assertion failed" message. You can use this to provide additional details about why the assertion failed. [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, "speed = %f, but the speed limit is 20" % speed) # Show a message with clarifying details [/codeblock]
Zapewnia, że warunek [code]condition[/code] jest spełniony. Jeśli [code]condition[/code] jest [code]false[/code], zostaje wygenerowany błąd i program jest wstrzymany dopóki go nie wznowisz. Wykonuje się tylko w kompilacjach debugowych lub przy uruchamianiu gry z edytora. Użyj tego w celach debugowych, by mieć pewność, że wyrażenie jest prawdziwie podczas rozwoju. Opcjonalny argument [code]message[/code] jeśli podany, jest pokazany oprócz generycznej wiadomości "Assertion failed". Możesz go użyć, by podać dodatkowe szczegóły dlaczego warunek się nie udał. [codeblock] # Wyobraź sobie, że zawsze chcemy mieć szybkość pomiędzy 0 i 20 szybkosc = -10 assert(szybkosc < 20) # Prawda, program będzie kontynuowany assert(szybkosc >= 0) # Fałsz, program się zatrzyma assert(szybkosc >= 0 && szybkosc < 20) # Możesz także łączyć dwa wyrażenia warunkowe w jednym sprawdzeniu assert(szybkosc < 20, "szybkosc = %f, ale limit to 20" % szybkosc) # Pokaż wiadomość uściślającą szczegóły [/codeblock]
[b]Note:[/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.
The optional [code]message[/code] argument, if given, is shown in addition to the generic "Assertion failed" message. You can use this to provide additional details about why the assertion failed.
[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, "speed = %f, but the speed limit is 20" % speed) # Show a message with clarifying details
[/codeblock]
Opcjonalny argument [code]message[/code] jeśli podany, jest pokazany oprócz generycznej wiadomości "Assertion failed". Możesz go użyć, by podać dodatkowe szczegóły dlaczego warunek się nie udał.
[codeblock]
# Wyobraź sobie, że zawsze chcemy mieć szybkość pomiędzy 0 i 20
szybkosc = -10
assert(szybkosc < 20) # Prawda, program będzie kontynuowany
assert(szybkosc >= 0) # Fałsz, program się zatrzyma
assert(szybkosc >= 0 && szybkosc < 20) # Możesz także łączyć dwa wyrażenia warunkowe w jednym sprawdzeniu
assert(szybkosc < 20, "szybkosc = %f, ale limit to 20" % szybkosc) # Pokaż wiadomość uściślającą szczegóły
[/codeblock]