Преглед изворни кода

Add missing docs for assert message in GDScript

Seems like this was overlooked in PR #31142. See also issue #17082.

(cherry picked from commit 4c3c73ef9c85a85ecc88b5671df50b564f275031)
Thomas ten Cate пре 5 година
родитељ
комит
c2469d0c6d
2 измењених фајлова са 7 додато и 1 уклоњено
  1. 5 1
      modules/gdscript/doc_classes/@GDScript.xml
  2. 2 0
      modules/gdscript/gdscript_editor.cpp

+ 5 - 1
modules/gdscript/doc_classes/@GDScript.xml

@@ -90,14 +90,18 @@
 			</return>
 			</return>
 			<argument index="0" name="condition" type="bool">
 			<argument index="0" name="condition" type="bool">
 			</argument>
 			</argument>
+			<argument index="1" name="message" type="String" default="&quot;&quot;">
+			</argument>
 			<description>
 			<description>
-				Asserts that the [code]condition[/code] is [code]true[/code] . If the [code]condition[/code] is [code]false[/code], an error is generated and the program is halted until you resume it. Only executes in debug builds, or when running the game from the editor. Use it for debugging purposes, to make sure a statement is [code]true[/code] during development.
+				Asserts that the [code]condition[/code] is [code]true[/code]. If the [code]condition[/code] is [code]false[/code], an error is generated and the program is halted until you resume it. Only executes in debug builds, or when running the game from the editor. Use it for debugging purposes, to make sure a statement is [code]true[/code] during development.
+				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]
 				[codeblock]
 				# Imagine we always want speed to be between 0 and 20
 				# Imagine we always want speed to be between 0 and 20
 				speed = -10
 				speed = -10
 				assert(speed &lt; 20) # True, the program will continue
 				assert(speed &lt; 20) # True, the program will continue
 				assert(speed &gt;= 0) # False, the program will stop
 				assert(speed &gt;= 0) # False, the program will stop
 				assert(speed &gt;= 0 &amp;&amp; speed &lt; 20) # You can also combine the two conditional statements in one check
 				assert(speed &gt;= 0 &amp;&amp; speed &lt; 20) # You can also combine the two conditional statements in one check
+				assert(speed &lt; 20, "speed = %f, but the speed limit is 20" % speed) # Show a message with clarifying details
 				[/codeblock]
 				[/codeblock]
 			</description>
 			</description>
 		</method>
 		</method>

+ 2 - 0
modules/gdscript/gdscript_editor.cpp

@@ -430,6 +430,8 @@ void GDScriptLanguage::get_public_functions(List<MethodInfo> *p_functions) const
 		mi.name = "assert";
 		mi.name = "assert";
 		mi.return_val.type = Variant::NIL;
 		mi.return_val.type = Variant::NIL;
 		mi.arguments.push_back(PropertyInfo(Variant::BOOL, "condition"));
 		mi.arguments.push_back(PropertyInfo(Variant::BOOL, "condition"));
+		mi.arguments.push_back(PropertyInfo(Variant::STRING, "message"));
+		mi.default_arguments.push_back(String());
 		p_functions->push_back(mi);
 		p_functions->push_back(mi);
 	}
 	}
 }
 }