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.
ادعا می کند که شرایط [code] [/ code] [کد] درست [/ code] است. اگر شرط [code] [/ code] [code] false [/ code] باشد ، خطایی ایجاد می شود و برنامه متوقف می شود تا زمانی که آن را از سر بگیرید. فقط در ساخت اشکال زدایی یا هنگام اجرای بازی از طریق ویرایشگر اجرا می شود. برای اطمینان از صحت یک عبارت [کد] درست در حین توسعه ، از آن برای اهداف اشکال زدایی استفاده کنید. آرگومان [کد] پیام [/ کد] اختیاری ، در صورت ارائه ، علاوه بر پیام عمومی "ادعا ناموفق است" نیز نشان داده می شود. برای ارائه جزئیات بیشتر درباره دلیل عدم موفقیت ادعا ، می توانید از این مورد استفاده کنید. [codeblock] # تصور کنید ما همیشه می خواهیم سرعت بین 0 تا 20 باشد سرعت = -10 assert (speed <20) # درست است ، برنامه ادامه خواهد یافت assert (speed> = 0) # false ، برنامه متوقف می شود assert (speed> = 0 && speed <20) # همچنین می توانید دو جمله شرطی را در یک چک ترکیب کنید ادعا (سرعت <20 ، "سرعت =٪ f ، اما سرعت مجاز 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.
آرگومان [کد] پیام [/ کد] اختیاری ، در صورت ارائه ، علاوه بر پیام عمومی "ادعا ناموفق است" نیز نشان داده می شود. برای ارائه جزئیات بیشتر درباره دلیل عدم موفقیت ادعا ، می توانید از این مورد استفاده کنید.
[codeblock]
# تصور کنید ما همیشه می خواهیم سرعت بین 0 تا 20 باشد
سرعت = -10
assert (speed <20) # درست است ، برنامه ادامه خواهد یافت
assert (speed> = 0) # false ، برنامه متوقف می شود
assert (speed> = 0 && speed <20) # همچنین می توانید دو جمله شرطی را در یک چک ترکیب کنید
ادعا (سرعت <20 ، "سرعت =٪ f ، اما سرعت مجاز 20"٪ سرعت است) # نمایش یک پیام با جزئیات شفاف
[/ codeblock]