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]の強力な形式として使用できます。 一般的な "Assertion failed" メッセージに加えて、オプションの [param message] を表示できます。こちらを使用して、アサーションが失敗した理由についての追加詳細を提供することが可能です。 [b]注意警告:[/b]エディタパフォーマンス上の理由から、[method assert] 内のコードは、デバッグ ビルドで、またはエディターからプロジェクトを実行するときにのみ実行されます。 [method assert] 呼び出しに副作用のあるコードを含めないでください。そうしないと、リリース モードでエクスポートしたときにプロジェクトの動作が異なります。 [codeblock] # speedを 0 から 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]
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.
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.
一般的な "Assertion failed" メッセージに加えて、オプションの [param message] を表示できます。こちらを使用して、アサーションが失敗した理由についての追加詳細を提供することが可能です。
[b]
注意警告:[/b]エディタパフォーマンス上の理由から、[method assert] 内のコードは、デバッグ ビルドで、またはエディターからプロジェクトを実行するときにのみ実行されます。 [method assert] 呼び出しに副作用のあるコードを含めないでください。そうしないと、リリース モードでエクスポートしたときにプロジェクトの動作が異なります。[codeblock]
# speedを 0 から 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]