Browse Source

GDScript: Fix return value of "lerp" builtin

Fixes #25082, fixes #24709.
Rémi Verschelde 6 years ago
parent
commit
d024979e84
3 changed files with 9 additions and 5 deletions
  1. 5 2
      doc/classes/@GDScript.xml
  2. 2 2
      doc/classes/Shape2D.xml
  3. 2 1
      modules/gdscript/gdscript_functions.cpp

+ 5 - 2
doc/classes/@GDScript.xml

@@ -539,7 +539,7 @@
 			</description>
 			</description>
 		</method>
 		</method>
 		<method name="lerp">
 		<method name="lerp">
-			<return type="float">
+			<return type="Variant">
 			</return>
 			</return>
 			<argument index="0" name="from" type="Variant">
 			<argument index="0" name="from" type="Variant">
 			</argument>
 			</argument>
@@ -549,8 +549,11 @@
 			</argument>
 			</argument>
 			<description>
 			<description>
 				Linearly interpolates between two values by a normalized value.
 				Linearly interpolates between two values by a normalized value.
+				If the [code]from[/code] and [code]to[/code] arguments are of type [int] or [float], the return value is a [float].
+				If both are of the same vector type ([Vector2], [Vector3] or [Color]), the return value will be of the same type ([code]lerp[/code] then calls the vector type's [code]linear_interpolate[/code] method).
 				[codeblock]
 				[codeblock]
-				lerp(1, 3, 0.5) # returns 2
+				lerp(0, 4, 0.75) # returns 3.0
+				lerp(Vector2(1, 5), Vector2(3, 2), 0.5) # returns Vector2(2, 3.5)
 				[/codeblock]
 				[/codeblock]
 			</description>
 			</description>
 		</method>
 		</method>

+ 2 - 2
doc/classes/Shape2D.xml

@@ -27,7 +27,7 @@
 			</description>
 			</description>
 		</method>
 		</method>
 		<method name="collide_and_get_contacts">
 		<method name="collide_and_get_contacts">
-			<return type="Variant">
+			<return type="Array">
 			</return>
 			</return>
 			<argument index="0" name="local_xform" type="Transform2D">
 			<argument index="0" name="local_xform" type="Transform2D">
 			</argument>
 			</argument>
@@ -59,7 +59,7 @@
 			</description>
 			</description>
 		</method>
 		</method>
 		<method name="collide_with_motion_and_get_contacts">
 		<method name="collide_with_motion_and_get_contacts">
-			<return type="Variant">
+			<return type="Array">
 			</return>
 			</return>
 			<argument index="0" name="local_xform" type="Transform2D">
 			<argument index="0" name="local_xform" type="Transform2D">
 			</argument>
 			</argument>

+ 2 - 1
modules/gdscript/gdscript_functions.cpp

@@ -1565,7 +1565,8 @@ MethodInfo GDScriptFunctions::get_info(Function p_func) {
 		} break;
 		} break;
 		case MATH_LERP: {
 		case MATH_LERP: {
 			MethodInfo mi("lerp", PropertyInfo(Variant::NIL, "from"), PropertyInfo(Variant::NIL, "to"), PropertyInfo(Variant::REAL, "weight"));
 			MethodInfo mi("lerp", PropertyInfo(Variant::NIL, "from"), PropertyInfo(Variant::NIL, "to"), PropertyInfo(Variant::REAL, "weight"));
-			mi.return_val.type = Variant::REAL;
+			mi.return_val.type = Variant::NIL;
+			mi.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT;
 			return mi;
 			return mi;
 		} break;
 		} break;
 		case MATH_INVERSE_LERP: {
 		case MATH_INVERSE_LERP: {