Open Flux159 opened 4 years ago
How about godot.round
and godot.ceil
?
godot.round
and godot.ceil
both are typed properly in godot.d.ts and function as expected on floats / error out on Vector3:
/** Rounds `s` upward, returning the smallest integral value that is not less than `s`.
i = ceil(1.45) # i is 2
i = ceil(1.001) # i is 2
*/
function ceil(s: number) : number;
/** Returns the integral value that is nearest to `s`, with halfway cases rounded away from zero.
round(2.6) # Returns 3
*/
function round(s: number) : number;
Trying to use a Vector3 ends up failing, but floats work fine:
console.log(godot.ceil(1.6)); // prints 2
// @ts-ignore
console.log(godot.ceil(new godot.Vector3(1.6, 0.6, 0.4)));
console.log(godot.round(1.4)); // prints 1
// @ts-ignore
console.log(godot.round(new godot.Vector3(1.6, 0.6, 0.4)));
E 0:00:01.510 call_method: JavaScript Error at round (native)
at _input (res://src/Cursor.jsx:32)
Call builtin function error round: Argument of type 'Vector3' is not assignable to parameter #0 of type 'float'
<C++ Source> modules/ECMAScript/quickjs/quickjs_binder.cpp:2125 @ call_method()
E 0:00:01.339 call_method: JavaScript Error at ceil (native)
at _input (res://src/Cursor.jsx:38)
Call builtin function error ceil: Argument of type 'Vector3' is not assignable to parameter #0 of type 'float'
<C++ Source> modules/ECMAScript/quickjs/quickjs_binder.cpp:2125 @ call_method()
Hi, getting an error trying to use godot.lerp for Vector3 types (positions).
The documentation in godot.d.ts says that the function should accept Vector2, Vector3, or Color arguments, but it seems like it's only expecting floats at runtime.
I was able to easily get around this by writing a vector3 lerp function in typescript, but it would be nice to be able to use the builtin function: