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]으로 더 강한 방식으로 오류를 알리는 데 사용될 수 있습니다. 선택적인 파리미터 [param message] 로 "Assertion failed" 메시지 외의 메시지를 추가적으로 표시할 수 있습니다. 이를 사용하여 assertion이 실패한 원인에 대한 추가적인 정보를 제공할 수 있습니다. [b]주의:[/b] 성능에 관한 이유로, 코드 안 [method assert] 는 디버그 빌드 모드에서 실행되거나 에디터에서 프로젝트를 실행할 때만 실행됩니다. [method assert] 호출에 작업 내용이 달라지는 코드를 작성하지 마십시오. 그렇지 않을 경우 프로젝트가 릴리즈 모드일 때 다르게 작동 될 수 있습니다. [codeblock] # 항상 속도가 0에서 20 사이이길 원한다면 speed = -10 assert(speed < 20) # True, 프로그램이 계속됩니다 assert(speed >= 0) # False, 프로그램이 정지됩니다 assert(speed >= 0 && speed < 20) # 두 가지 조건을 한 번에 확인하도록 조합할 수 있습니다. assert(speed < 20, "the speed limit is 20") # 메시지를 보여줍니다 [/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.
선택적인 파리미터 [param message] 로 "Assertion failed" 메시지 외의 메시지를 추가적으로 표시할 수 있습니다. 이를 사용하여 assertion이 실패한 원인에 대한 추가적인 정보를 제공할 수 있습니다.
[b]주의:[/b] 성능에 관한 이유로, 코드 안 [method assert] 는 디버그 빌드 모드에서 실행되거나 에디터에서 프로젝트를 실행할 때만 실행됩니다. [method assert] 호출에 작업 내용이 달라지는 코드를 작성하지 마십시오. 그렇지 않을 경우 프로젝트가 릴리즈 모드일 때 다르게 작동 될 수 있습니다.
[codeblock]
# 항상 속도가 0에서 20 사이이길 원한다면
speed = -10
assert(speed < 20) # True, 프로그램이 계속됩니다
assert(speed >= 0) # False, 프로그램이 정지됩니다
assert(speed >= 0 && speed < 20) # 두 가지 조건을 한 번에 확인하도록 조합할 수 있습니다.
assert(speed < 20, "the speed limit is 20") # 메시지를 보여줍니다
[/codeblock]