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] false [/code] ، إنشاء خطأ. عند التشغيل من المحرر ، سيتم أيضا إيقاف المشروع قيد التشغيل مؤقتا حتى تستأنفه. يمكن استخدام هذا كشكل أقوى من [الأسلوب @GlobalScope.push_error] للإبلاغ عن الأخطاء لمطوري المشروع أو مستخدمي الوظائف الإضافية. يمكن عرض [رسالة معلمة] اختيارية بالإضافة إلى الرسالة العامة "فشل التأكيد". يمكنك استخدام هذا لتقديم تفاصيل إضافية حول سبب فشل التأكيد. [b] تحذير: [/b] لأسباب تتعلق بالأداء ، يتم تنفيذ التعليمات البرمجية الموجودة داخل [تأكيد الطريقة] فقط في إصدارات التصحيح أو عند تشغيل المشروع من المحرر. لا تقم بتضمين التعليمات البرمجية التي لها آثار جانبية في استدعاء [تأكيد الطريقة]. خلاف ذلك ، سيتصرف المشروع بشكل مختلف عند تصديره في وضع الإصدار. [كودبلوك] # تخيل أننا نريد دائما أن تكون السرعة بين 0 و 20. سرعة VAR = -10 تأكيد (السرعة < 20) # صحيح ، سيستمر البرنامج. تأكيد (السرعة > = 0) # خطأ ، سيتوقف البرنامج. تأكيد (السرعة > = 0 والسرعة < 20) # يمكنك أيضا دمج العبارتين الشرطيتين في شيك واحد. تأكيد (السرعة < 20 ، "الحد الأقصى للسرعة هو 20") # إظهار رسالة. [/ كودبلوك]
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] تحذير: [/b] لأسباب تتعلق بالأداء ، يتم تنفيذ التعليمات البرمجية الموجودة داخل [تأكيد الطريقة] فقط في إصدارات التصحيح أو عند تشغيل المشروع من المحرر. لا تقم بتضمين التعليمات البرمجية التي لها آثار جانبية في استدعاء [تأكيد الطريقة]. خلاف ذلك ، سيتصرف المشروع بشكل مختلف عند تصديره في وضع الإصدار.
[كودبلوك]
# تخيل أننا نريد دائما أن تكون السرعة بين 0 و 20.
سرعة VAR = -10
تأكيد (السرعة < 20) # صحيح ، سيستمر البرنامج. تأكيد (السرعة > = 0) # خطأ ، سيتوقف البرنامج.
تأكيد (السرعة > = 0 والسرعة < 20) # يمكنك أيضا دمج العبارتين الشرطيتين في شيك واحد.
تأكيد (السرعة < 20 ، "الحد الأقصى للسرعة هو 20") # إظهار رسالة.
[/ كودبلوك]