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.
Potvrzuje, že [code]condition[/code] je [code]true[/code]. Pokud je [code]condition[/code][code]false[/code], výsledkem bude chyba. Při spuštění z editoru bude spuštěný projekt rovněž pozastaven, dokud jej neobnovíte. Může být použito jako důraznější forma [method push_error] pro nahlášení chyb vývojářům projektu nebo uživatelům rozšíření. [b]Poznámka:[/b] Z výkonnostních důvodů se kód uvnitř [method assert] provádí pouze v ladících sestaveních nebo při spuštění projektu z editoru. Do volání [method assert] nezařazujte kód, který má vedlejší účinky. Jinak se projekt bude při exportu v režimu vydání chovat jinak. Nepovinný argument [code]message[/code], je-li zadán, se zobrazí navíc k obecné zprávě "Assertion failed". Můžete jej použít k uvedení dalších podrobností o tom, proč tvrzení selhalo. [codeblock] # Představme si, že vždy chceme, aby rychlost byla mezi 0 a 20. speed = -10 assert(speed < 20) # True, program bude pokračovat assert(speed >= 0) # False, program se ukončí assert(speed >= 0 && speed < 20) # Můžete také skombinovat obě dvě podmínky do jednoho tvrzení assert(speed < 20, "speed = %f, but the speed limit is 20" % speed) # Vypíše zprávu, která objasňuje detaily [/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.
[b]Poznámka:[/b] Z výkonnostních důvodů se kód uvnitř [method assert] provádí pouze v ladících sestaveních nebo při spuštění projektu z editoru. Do volání [method assert] nezařazujte kód, který má vedlejší účinky. Jinak se projekt bude při exportu v režimu vydání chovat jinak.
Nepovinný argument [code]message[/code], je-li zadán, se zobrazí navíc k obecné zprávě "Assertion failed". Můžete jej použít k uvedení dalších podrobností o tom, proč tvrzení selhalo.
[codeblock]
# Představme si, že vždy chceme, aby rychlost byla mezi 0 a 20.
speed = -10
assert(speed < 20) # True, program bude pokračovat
assert(speed >= 0) # False, program se ukončí
assert(speed >= 0 && speed < 20) # Můžete také skombinovat obě dvě podmínky do jednoho tvrzení
assert(speed < 20, "speed = %f, but the speed limit is 20" % speed) # Vypíše zprávu, která objasňuje detaily
[/codeblock]