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.
Controlla che [code]condizion[/code] sia [code]true[/code](vero). Se [code]condition[/code] è [code]false[/code](falso), un errore è generato.Quando eseguito all'interno dell'editor, il progetto verrà anche messo in pausa, finchè non lo farai ripartire. Ciò può essere usato come un migliore sistema di [method push_error] per riportare errori agli sviluppatori del progetto o ulteriori utenti. [b]Nota bene:[/b] Per motivi di prestazioni, il codice all'interno di [method assert] è eseguito solo nelle build di debug o quando il progetto è eseguito dall'editor. Non scrivere codice che dovrà avere effetti collaterali in una chiamata [method assert]. Altrimenti il progetto si comporterà in modo diverso quando esportato in modalità release. L'argomento opzionale [code]message[/code], se dato, è mostrato in aggiunta al generico messaggio "Assertion failed" (Asserzione fallita). Può essere usato per fornire più dettagli sul motivo per cui un asserzione ha fallito. [codeblock] # Immaginati di voler sempre avere una velocità (speed nel caso nostro) sempre tra 0 e 20 speed = -10 assert(speed < 20) # Vero(True), il programma continuerà assert(speed >= 0) # Falso(False), il programma si fermerà assert(speed >= 0 && speed < 20) # Puoi anche combinare due condizioni in un singolo controllo assert(speed < 20, "speed = %f, but the speed limit is 20" % speed) # Mostra un messaggio per chiarire i dettagli [/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]Nota bene:[/b] Per motivi di prestazioni, il codice all'interno di [method assert] è eseguito solo nelle build di debug o quando il progetto è eseguito dall'editor. Non scrivere codice che dovrà avere effetti collaterali in una chiamata [method assert]. Altrimenti il progetto si comporterà in modo diverso quando esportato in modalità release.
L'argomento opzionale [code]message[/code], se dato, è mostrato in aggiunta al generico messaggio "Assertion failed" (Asserzione fallita). Può essere usato per fornire più dettagli sul motivo per cui un asserzione ha fallito.
[codeblock]
# Immaginati di voler sempre avere una velocità (speed nel caso nostro) sempre tra 0 e 20
speed = -10
assert(speed < 20) # Vero(True), il programma continuerà
assert(speed >= 0) # Falso(False), il programma si fermerà
assert(speed >= 0 && speed < 20) # Puoi anche combinare due condizioni in un singolo controllo
assert(speed < 20, "speed = %f, but the speed limit is 20" % speed) # Mostra un messaggio per chiarire i dettagli
[/codeblock]