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]
[code]condition[/code] 이 [code]true[/code] 인지 확인한다. [code]condition[/code] 이 [code]false[/code] 이면, 오류가 발생하고 사용자가 다시 시작할 때까지 프로그램이 정지된다. 디버그 빌드나 에디터에서 게임이 실행될 때만 실행된다. 디버깅 목적으로만 사용하고, 개발 중에 상태가 [code]true[/code] 인지 확인할 수 있게 한다. 옵션으로 [code]message[/code] 인수를 넣으면 "Assertion failed" 메시지를 보여준다. assertion이 실패한 원인에 대한 추가적인 상세 정보를 제공하려면 이것을 사용하면 된다. [codeblock] # 항상 속도가 0에서 20 사이이길 원한다면 speed = -10 assert(speed < 20) # True, 프로그램이 계속된다 assert(speed >= 0) # False, 프로그램이 정지된다 assert(speed >= 0 && speed < 20) # 두 가지 조건을 한 번에 확인하도록 조합할 수 있다 assert(speed < 20, "speed = %f, but the speed limit is 20" % speed) # 명확한 상세 정보로 메시지를 보여준다 [/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]
옵션으로 [code]message[/code] 인수를 넣으면 "Assertion failed" 메시지를 보여준다. assertion이 실패한 원인에 대한 추가적인 상세 정보를 제공하려면 이것을 사용하면 된다.
[codeblock]
# 항상 속도가 0에서 20 사이이길 원한다면
speed = -10
assert(speed < 20) # True, 프로그램이 계속된다
assert(speed >= 0) # False, 프로그램이 정지된다
assert(speed >= 0 && speed < 20) # 두 가지 조건을 한 번에 확인하도록 조합할 수 있다
assert(speed < 20, "speed = %f, but the speed limit is 20" % speed) # 명확한 상세 정보로 메시지를 보여준다
[/codeblock]