You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-05 12:10:55 +00:00
GDScript: add an optional message parameter to assert()
Before this patch, assert() only took the condition to assert on:
assert(item_data)
Now, it can optionally take a string that will be printed upon failure:
assert(item_data, item_name + " has no item data in ItemDatabase")
This makes it easier to immediately see what the issue is by being
able to write informative failure messages.
Thanks to @wiped1 for sharing their patch, upon which this is based.
Closes #17082
This commit is contained in:
@@ -1475,20 +1475,25 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
|
||||
DISPATCH_OPCODE;
|
||||
|
||||
OPCODE(OPCODE_ASSERT) {
|
||||
CHECK_SPACE(2);
|
||||
CHECK_SPACE(3);
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
GET_VARIANT_PTR(test, 1);
|
||||
GET_VARIANT_PTR(message, 2);
|
||||
bool result = test->booleanize();
|
||||
|
||||
if (!result) {
|
||||
|
||||
err_text = "Assertion failed.";
|
||||
const String &message_str = *message;
|
||||
if (message_str.empty()) {
|
||||
err_text = "Assertion failed.";
|
||||
} else {
|
||||
err_text = "Assertion failed: " + message_str;
|
||||
}
|
||||
OPCODE_BREAK;
|
||||
}
|
||||
|
||||
#endif
|
||||
ip += 2;
|
||||
ip += 3;
|
||||
}
|
||||
DISPATCH_OPCODE;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user