2017-09-12 22:42:36 +02:00
<?xml version="1.0" encoding="UTF-8" ?>
2021-04-26 13:14:51 +02:00
<class name= "@GDScript" version= "3.4" >
2017-09-12 22:42:36 +02:00
<brief_description >
Built-in GDScript functions.
</brief_description>
<description >
2018-06-18 04:25:27 +02:00
List of core built-in GDScript functions. Math functions and other utilities. Everything else is provided by objects. (Keywords: builtin, built in, global functions.)
2017-09-12 22:42:36 +02:00
</description>
<tutorials >
</tutorials>
<methods >
<method name= "Color8" >
2021-07-30 15:28:05 +02:00
<return type= "Color" />
<argument index= "0" name= "r8" type= "int" />
<argument index= "1" name= "g8" type= "int" />
<argument index= "2" name= "b8" type= "int" />
<argument index= "3" name= "a8" type= "int" default= "255" />
2017-09-12 22:42:36 +02:00
<description >
2019-11-02 09:48:08 +01:00
Returns a color constructed from integer red, green, blue, and alpha channels. Each channel should have 8 bits of information ranging from 0 to 255.
2017-09-18 00:36:34 +02:00
[code]r8[/code] red channel
[code]g8[/code] green channel
[code]b8[/code] blue channel
[code]a8[/code] alpha channel
2017-09-12 22:42:36 +02:00
[codeblock]
red = Color8(255, 0, 0)
[/codeblock]
</description>
</method>
<method name= "ColorN" >
2021-07-30 15:28:05 +02:00
<return type= "Color" />
<argument index= "0" name= "name" type= "String" />
<argument index= "1" name= "alpha" type= "float" default= "1.0" />
2017-09-12 22:42:36 +02:00
<description >
2020-01-26 12:07:59 +01:00
Returns a color according to the standardized [code]name[/code] with [code]alpha[/code] ranging from 0 to 1.
2017-09-12 22:42:36 +02:00
[codeblock]
2018-01-07 19:43:50 +01:00
red = ColorN("red", 1)
2017-09-12 22:42:36 +02:00
[/codeblock]
2020-01-26 12:07:59 +01:00
Supported color names are the same as the constants defined in [Color].
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "abs" >
2021-07-30 15:28:05 +02:00
<return type= "float" />
<argument index= "0" name= "s" type= "float" />
2017-09-12 22:42:36 +02:00
<description >
2020-07-22 03:21:41 +02:00
Returns the absolute value of parameter [code]s[/code] (i.e. positive value).
2017-09-12 22:42:36 +02:00
[codeblock]
2020-11-29 15:08:45 +01:00
a = abs(-1) # a is 1
2017-09-12 22:42:36 +02:00
[/codeblock]
</description>
</method>
<method name= "acos" >
2021-07-30 15:28:05 +02:00
<return type= "float" />
<argument index= "0" name= "s" type= "float" />
2017-09-12 22:42:36 +02:00
<description >
2021-03-15 17:25:22 +01:00
Returns the arc cosine of [code]s[/code] in radians. Use to get the angle of cosine [code]s[/code]. [code]s[/code] must be between [code]-1.0[/code] and [code]1.0[/code] (inclusive), otherwise, [method acos] will return [constant NAN].
2017-09-12 22:42:36 +02:00
[codeblock]
# c is 0.523599 or 30 degrees if converted with rad2deg(s)
c = acos(0.866025)
[/codeblock]
</description>
</method>
<method name= "asin" >
2021-07-30 15:28:05 +02:00
<return type= "float" />
<argument index= "0" name= "s" type= "float" />
2017-09-12 22:42:36 +02:00
<description >
2021-03-15 17:25:22 +01:00
Returns the arc sine of [code]s[/code] in radians. Use to get the angle of sine [code]s[/code]. [code]s[/code] must be between [code]-1.0[/code] and [code]1.0[/code] (inclusive), otherwise, [method asin] will return [constant NAN].
2017-09-12 22:42:36 +02:00
[codeblock]
# s is 0.523599 or 30 degrees if converted with rad2deg(s)
2017-09-13 08:18:51 +02:00
s = asin(0.5)
2017-09-12 22:42:36 +02:00
[/codeblock]
</description>
</method>
<method name= "assert" >
2021-07-30 15:28:05 +02:00
<return type= "void" />
<argument index= "0" name= "condition" type= "bool" />
<argument index= "1" name= "message" type= "String" default= """" />
2017-09-12 22:42:36 +02:00
<description >
2020-11-09 21:48:24 +01:00
Asserts that the [code]condition[/code] is [code]true[/code]. If the [code]condition[/code] 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 push_error] for reporting errors to project developers or add-on users.
[b]Note:[/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.
2020-03-31 10:39:23 +02:00
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.
2017-09-13 08:18:51 +02:00
[codeblock]
2020-11-09 21:48:24 +01:00
# Imagine we always want speed to be between 0 and 20.
var speed = -10
2019-06-03 12:27:37 +02:00
assert(speed < 20) # True, the program will continue
assert(speed > = 0) # False, the program will stop
2020-11-09 21:48:24 +01:00
assert(speed > = 0 and speed < 20) # You can also combine the two conditional statements in one check
2020-03-31 10:39:23 +02:00
assert(speed < 20, "speed = %f, but the speed limit is 20" % speed) # Show a message with clarifying details
2017-09-13 08:18:51 +02:00
[/codeblock]
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "atan" >
2021-07-30 15:28:05 +02:00
<return type= "float" />
<argument index= "0" name= "s" type= "float" />
2017-09-12 22:42:36 +02:00
<description >
2017-09-18 00:36:34 +02:00
Returns the arc tangent of [code]s[/code] in radians. Use it to get the angle from an angle's tangent in trigonometry: [code]atan(tan(angle)) == angle[/code].
2020-07-30 16:26:45 +02:00
The method cannot know in which quadrant the angle should fall. See [method atan2] if you have both [code]y[/code] and [code]x[/code].
2017-09-13 08:18:51 +02:00
[codeblock]
a = atan(0.5) # a is 0.463648
[/codeblock]
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "atan2" >
2021-07-30 15:28:05 +02:00
<return type= "float" />
<argument index= "0" name= "y" type= "float" />
<argument index= "1" name= "x" type= "float" />
2017-09-12 22:42:36 +02:00
<description >
2017-09-18 00:36:34 +02:00
Returns the arc tangent of [code]y/x[/code] in radians. Use to get the angle of tangent [code]y/x[/code]. To compute the value, the method takes into account the sign of both arguments in order to determine the quadrant.
2020-07-22 03:21:41 +02:00
Important note: The Y coordinate comes first, by convention.
2017-09-12 22:42:36 +02:00
[codeblock]
2019-03-27 17:13:37 +01:00
a = atan2(0, -1) # a is 3.141593
2017-09-12 22:42:36 +02:00
[/codeblock]
</description>
</method>
<method name= "bytes2var" >
2021-07-30 15:28:05 +02:00
<return type= "Variant" />
<argument index= "0" name= "bytes" type= "PoolByteArray" />
<argument index= "1" name= "allow_objects" type= "bool" default= "false" />
2017-09-12 22:42:36 +02:00
<description >
2019-03-26 16:52:42 +01:00
Decodes a byte array back to a value. When [code]allow_objects[/code] is [code]true[/code] decoding objects is allowed.
[b]WARNING:[/b] Deserialized object can contain code which gets executed. Do not use this option if the serialized object comes from untrusted sources to avoid potential security threats (remote code execution).
2017-09-12 22:42:36 +02:00
</description>
</method>
2017-10-13 01:15:45 +02:00
<method name= "cartesian2polar" >
2021-07-30 15:28:05 +02:00
<return type= "Vector2" />
<argument index= "0" name= "x" type= "float" />
<argument index= "1" name= "y" type= "float" />
2017-10-13 01:15:45 +02:00
<description >
2019-06-22 01:04:47 +02:00
Converts a 2D point expressed in the cartesian coordinate system (X and Y axis) to the polar coordinate system (a distance from the origin and an angle).
2017-10-13 01:15:45 +02:00
</description>
</method>
2017-09-12 22:42:36 +02:00
<method name= "ceil" >
2021-07-30 15:28:05 +02:00
<return type= "float" />
<argument index= "0" name= "s" type= "float" />
2017-09-12 22:42:36 +02:00
<description >
2020-07-22 03:21:41 +02:00
Rounds [code]s[/code] upward (towards positive infinity), returning the smallest whole number that is not less than [code]s[/code].
2017-09-12 22:42:36 +02:00
[codeblock]
2020-11-29 15:08:45 +01:00
a = ceil(1.45) # a is 2.0
a = ceil(1.001) # a is 2.0
2017-09-12 22:42:36 +02:00
[/codeblock]
2020-11-29 15:08:45 +01:00
See also [method floor], [method round], [method stepify], and [int].
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "char" >
2021-07-30 15:28:05 +02:00
<return type= "String" />
<argument index= "0" name= "code" type= "int" />
2017-09-12 22:42:36 +02:00
<description >
2019-12-15 04:10:29 +01:00
Returns a character as a String of the given Unicode code point (which is compatible with ASCII code).
2017-09-12 22:42:36 +02:00
[codeblock]
2019-06-22 01:04:47 +02:00
a = char(65) # a is "A"
a = char(65 + 32) # a is "a"
2019-12-15 04:10:29 +01:00
a = char(8364) # a is "€"
2017-09-12 22:42:36 +02:00
[/codeblock]
2019-12-15 04:10:29 +01:00
This is the inverse of [method ord].
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "clamp" >
2021-07-30 15:28:05 +02:00
<return type= "float" />
<argument index= "0" name= "value" type= "float" />
<argument index= "1" name= "min" type= "float" />
<argument index= "2" name= "max" type= "float" />
2017-09-12 22:42:36 +02:00
<description >
2018-01-17 11:28:59 +01:00
Clamps [code]value[/code] and returns a value not less than [code]min[/code] and not more than [code]max[/code].
2017-09-12 22:42:36 +02:00
[codeblock]
2020-11-29 15:08:45 +01:00
a = clamp(1000, 1, 20) # a is 20
a = clamp(-10, 1, 20) # a is 1
a = clamp(15, 1, 20) # a is 15
2017-09-12 22:42:36 +02:00
[/codeblock]
</description>
</method>
<method name= "convert" >
2021-07-30 15:28:05 +02:00
<return type= "Variant" />
<argument index= "0" name= "what" type= "Variant" />
<argument index= "1" name= "type" type= "int" />
2017-09-12 22:42:36 +02:00
<description >
2019-12-06 23:09:20 +01:00
Converts from a type to another in the best way possible. The [code]type[/code] parameter uses the [enum Variant.Type] values.
2017-09-12 22:42:36 +02:00
[codeblock]
a = Vector2(1, 0)
2019-06-22 01:04:47 +02:00
# Prints 1
2017-09-12 22:42:36 +02:00
print(a.length())
a = convert(a, TYPE_STRING)
2019-06-22 01:04:47 +02:00
# Prints 6 as "(1, 0)" is 6 characters
2017-09-12 22:42:36 +02:00
print(a.length())
[/codeblock]
</description>
</method>
<method name= "cos" >
2021-07-30 15:28:05 +02:00
<return type= "float" />
<argument index= "0" name= "s" type= "float" />
2017-09-12 22:42:36 +02:00
<description >
2017-09-18 00:36:34 +02:00
Returns the cosine of angle [code]s[/code] in radians.
2017-09-12 22:42:36 +02:00
[codeblock]
2020-11-29 15:08:45 +01:00
a = cos(TAU) # a is 1.0
a = cos(PI) # a is -1.0
2017-09-12 22:42:36 +02:00
[/codeblock]
</description>
</method>
<method name= "cosh" >
2021-07-30 15:28:05 +02:00
<return type= "float" />
<argument index= "0" name= "s" type= "float" />
2017-09-12 22:42:36 +02:00
<description >
2017-09-18 00:36:34 +02:00
Returns the hyperbolic cosine of [code]s[/code] in radians.
2017-09-12 22:42:36 +02:00
[codeblock]
2020-11-29 15:08:45 +01:00
print(cosh(1)) # Prints 1.543081
2017-09-12 22:42:36 +02:00
[/codeblock]
</description>
</method>
<method name= "db2linear" >
2021-07-30 15:28:05 +02:00
<return type= "float" />
<argument index= "0" name= "db" type= "float" />
2017-09-12 22:42:36 +02:00
<description >
2017-09-18 00:36:34 +02:00
Converts from decibels to linear energy (audio).
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "decimals" >
2021-07-30 15:28:05 +02:00
<return type= "int" />
<argument index= "0" name= "step" type= "float" />
2017-09-12 22:42:36 +02:00
<description >
2019-06-22 01:04:47 +02:00
Deprecated alias for [method step_decimals].
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "dectime" >
2021-07-30 15:28:05 +02:00
<return type= "float" />
<argument index= "0" name= "value" type= "float" />
<argument index= "1" name= "amount" type= "float" />
<argument index= "2" name= "step" type= "float" />
2017-09-12 22:42:36 +02:00
<description >
2017-09-18 00:36:34 +02:00
Returns the result of [code]value[/code] decreased by [code]step[/code] * [code]amount[/code].
2017-09-12 22:42:36 +02:00
[codeblock]
2020-11-29 15:08:45 +01:00
a = dectime(60, 10, 0.1)) # a is 59.0
2017-09-12 22:42:36 +02:00
[/codeblock]
</description>
</method>
<method name= "deg2rad" >
2021-07-30 15:28:05 +02:00
<return type= "float" />
<argument index= "0" name= "deg" type= "float" />
2017-09-12 22:42:36 +02:00
<description >
2020-07-22 03:21:41 +02:00
Converts an angle expressed in degrees to radians.
2017-09-12 22:42:36 +02:00
[codeblock]
2020-11-29 15:08:45 +01:00
r = deg2rad(180) # r is 3.141593
2017-09-12 22:42:36 +02:00
[/codeblock]
</description>
</method>
<method name= "dict2inst" >
2021-07-30 15:28:05 +02:00
<return type= "Object" />
<argument index= "0" name= "dict" type= "Dictionary" />
2017-09-12 22:42:36 +02:00
<description >
2020-11-29 15:08:45 +01:00
Converts a dictionary (previously created with [method inst2dict]) back to an instance. Useful for deserializing.
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "ease" >
2021-07-30 15:28:05 +02:00
<return type= "float" />
<argument index= "0" name= "s" type= "float" />
<argument index= "1" name= "curve" type= "float" />
2017-09-12 22:42:36 +02:00
<description >
2020-07-22 03:21:41 +02:00
Easing function, based on exponent. The curve values are: 0 is constant, 1 is linear, 0 to 1 is ease-in, 1+ is ease out. Negative values are in-out/out in.
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "exp" >
2021-07-30 15:28:05 +02:00
<return type= "float" />
<argument index= "0" name= "s" type= "float" />
2017-09-12 22:42:36 +02:00
<description >
2018-04-15 18:40:31 +02:00
The natural exponential function. It raises the mathematical constant [b]e[/b] to the power of [code]s[/code] and returns it.
2020-07-25 16:11:23 +02:00
[b]e[/b] has an approximate value of 2.71828, and can be obtained with [code]exp(1)[/code].
2019-07-29 07:53:37 +02:00
For exponents to other bases use the method [method pow].
2017-09-13 08:18:51 +02:00
[codeblock]
2019-06-22 01:04:47 +02:00
a = exp(2) # Approximately 7.39
2017-09-13 08:18:51 +02:00
[/codeblock]
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "floor" >
2021-07-30 15:28:05 +02:00
<return type= "float" />
<argument index= "0" name= "s" type= "float" />
2017-09-12 22:42:36 +02:00
<description >
2020-07-22 03:21:41 +02:00
Rounds [code]s[/code] downward (towards negative infinity), returning the largest whole number that is not more than [code]s[/code].
2017-09-13 08:18:51 +02:00
[codeblock]
2020-11-29 15:08:45 +01:00
a = floor(2.45) # a is 2.0
a = floor(2.99) # a is 2.0
a = floor(-2.99) # a is -3.0
2017-09-13 08:18:51 +02:00
[/codeblock]
2020-11-29 15:08:45 +01:00
See also [method ceil], [method round], [method stepify], and [int].
[b]Note:[/b] This method returns a float. If you need an integer and [code]s[/code] is a non-negative number, you can use [code]int(s)[/code] directly.
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "fmod" >
2021-07-30 15:28:05 +02:00
<return type= "float" />
<argument index= "0" name= "a" type= "float" />
<argument index= "1" name= "b" type= "float" />
2017-09-12 22:42:36 +02:00
<description >
2018-10-27 22:12:27 +02:00
Returns the floating-point remainder of [code]a/b[/code], keeping the sign of [code]a[/code].
2017-09-12 22:42:36 +02:00
[codeblock]
2020-11-29 15:08:45 +01:00
r = fmod(7, 5.5) # r is 1.5
2017-09-12 22:42:36 +02:00
[/codeblock]
2018-10-27 22:12:27 +02:00
For the integer remainder operation, use the % operator.
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "fposmod" >
2021-07-30 15:28:05 +02:00
<return type= "float" />
<argument index= "0" name= "a" type= "float" />
<argument index= "1" name= "b" type= "float" />
2018-10-27 22:12:27 +02:00
<description >
Returns the floating-point modulus of [code]a/b[/code] that wraps equally in positive and negative.
[codeblock]
2020-09-14 18:19:30 +02:00
for i in 7:
var x = 0.5 * i - 1.5
print("%4.1f %4.1f %4.1f" % [x, fmod(x, 1.5), fposmod(x, 1.5)])
2018-10-27 22:12:27 +02:00
[/codeblock]
Produces:
[codeblock]
2020-09-14 18:19:30 +02:00
-1.5 -0.0 0.0
-1.0 -1.0 0.5
-0.5 -0.5 1.0
0.0 0.0 0.0
0.5 0.5 0.5
1.0 1.0 1.0
1.5 0.0 0.0
2018-10-27 22:12:27 +02:00
[/codeblock]
</description>
</method>
2017-09-12 22:42:36 +02:00
<method name= "funcref" >
2021-07-30 15:28:05 +02:00
<return type= "FuncRef" />
<argument index= "0" name= "instance" type= "Object" />
<argument index= "1" name= "funcname" type= "String" />
2017-09-12 22:42:36 +02:00
<description >
2017-09-18 00:36:34 +02:00
Returns a reference to the specified function [code]funcname[/code] in the [code]instance[/code] node. As functions aren't first-class objects in GDscript, use [code]funcref[/code] to store a [FuncRef] in a variable and call it later.
2017-09-13 08:18:51 +02:00
[codeblock]
func foo():
return("bar")
a = funcref(self, "foo")
2019-06-22 01:04:47 +02:00
print(a.call_func()) # Prints bar
2017-09-13 08:18:51 +02:00
[/codeblock]
2017-09-12 22:42:36 +02:00
</description>
</method>
2018-07-26 11:56:21 +02:00
<method name= "get_stack" >
2021-07-30 15:28:05 +02:00
<return type= "Array" />
2018-07-26 11:56:21 +02:00
<description >
2019-01-06 13:57:23 +01:00
Returns an array of dictionaries representing the current call stack.
[codeblock]
func _ready():
foo()
func foo():
bar()
func bar():
print(get_stack())
[/codeblock]
would print
[codeblock]
[{function:bar, line:12, source:res://script.gd}, {function:foo, line:9, source:res://script.gd}, {function:_ready, line:6, source:res://script.gd}]
[/codeblock]
2018-07-26 11:56:21 +02:00
</description>
</method>
2017-09-12 22:42:36 +02:00
<method name= "hash" >
2021-07-30 15:28:05 +02:00
<return type= "int" />
<argument index= "0" name= "var" type= "Variant" />
2017-09-12 22:42:36 +02:00
<description >
Returns the integer hash of the variable passed.
[codeblock]
2019-06-22 01:04:47 +02:00
print(hash("a")) # Prints 177670
2017-09-12 22:42:36 +02:00
[/codeblock]
</description>
</method>
<method name= "inst2dict" >
2021-07-30 15:28:05 +02:00
<return type= "Dictionary" />
<argument index= "0" name= "inst" type= "Object" />
2017-09-12 22:42:36 +02:00
<description >
2017-09-18 00:36:34 +02:00
Returns the passed instance converted to a dictionary (useful for serializing).
2017-09-12 22:42:36 +02:00
[codeblock]
var foo = "bar"
func _ready():
var d = inst2dict(self)
print(d.keys())
print(d.values())
[/codeblock]
Prints out:
[codeblock]
[@subpath, @path, foo]
[, res://test.gd, bar]
[/codeblock]
</description>
</method>
<method name= "instance_from_id" >
2021-07-30 15:28:05 +02:00
<return type= "Object" />
<argument index= "0" name= "instance_id" type= "int" />
2017-09-12 22:42:36 +02:00
<description >
2017-09-18 00:36:34 +02:00
Returns the Object that corresponds to [code]instance_id[/code]. All Objects have a unique instance ID.
2017-09-12 22:42:36 +02:00
[codeblock]
var foo = "bar"
func _ready():
var id = get_instance_id()
var inst = instance_from_id(id)
2019-06-22 01:04:47 +02:00
print(inst.foo) # Prints bar
2017-09-12 22:42:36 +02:00
[/codeblock]
</description>
</method>
<method name= "inverse_lerp" >
2021-07-30 15:28:05 +02:00
<return type= "float" />
<argument index= "0" name= "from" type= "float" />
<argument index= "1" name= "to" type= "float" />
<argument index= "2" name= "weight" type= "float" />
2017-09-12 22:42:36 +02:00
<description >
2020-02-27 22:49:05 +01:00
Returns a normalized value considering the given range. This is the opposite of [method lerp].
2017-09-12 22:42:36 +02:00
[codeblock]
2020-02-27 22:49:05 +01:00
var middle = lerp(20, 30, 0.75)
# `middle` is now 27.5.
# Now, we pretend to have forgotten the original ratio and want to get it back.
var ratio = inverse_lerp(20, 30, 27.5)
# `ratio` is now 0.75.
2017-09-12 22:42:36 +02:00
[/codeblock]
</description>
</method>
2018-08-01 01:34:20 +02:00
<method name= "is_equal_approx" >
2021-07-30 15:28:05 +02:00
<return type= "bool" />
<argument index= "0" name= "a" type= "float" />
<argument index= "1" name= "b" type= "float" />
2018-08-01 01:34:20 +02:00
<description >
2019-11-30 21:08:50 +01:00
Returns [code]true[/code] if [code]a[/code] and [code]b[/code] are approximately equal to each other.
2020-07-25 16:11:23 +02:00
Here, approximately equal means that [code]a[/code] and [code]b[/code] are within a small internal epsilon of each other, which scales with the magnitude of the numbers.
Infinity values of the same sign are considered equal.
2018-08-01 01:34:20 +02:00
</description>
</method>
2017-09-12 22:42:36 +02:00
<method name= "is_inf" >
2021-07-30 15:28:05 +02:00
<return type= "bool" />
<argument index= "0" name= "s" type= "float" />
2017-09-12 22:42:36 +02:00
<description >
2019-01-06 13:57:23 +01:00
Returns whether [code]s[/code] is an infinity value (either positive infinity or negative infinity).
2017-09-12 22:42:36 +02:00
</description>
</method>
2018-05-12 09:38:00 +02:00
<method name= "is_instance_valid" >
2021-07-30 15:28:05 +02:00
<return type= "bool" />
<argument index= "0" name= "instance" type= "Object" />
2018-05-12 09:38:00 +02:00
<description >
2019-01-06 13:57:23 +01:00
Returns whether [code]instance[/code] is a valid object (e.g. has not been deleted from memory).
2018-05-12 09:38:00 +02:00
</description>
</method>
2017-09-12 22:42:36 +02:00
<method name= "is_nan" >
2021-07-30 15:28:05 +02:00
<return type= "bool" />
<argument index= "0" name= "s" type= "float" />
2017-09-12 22:42:36 +02:00
<description >
2020-07-22 03:21:41 +02:00
Returns whether [code]s[/code] is a NaN ("Not a Number" or invalid) value.
2017-09-12 22:42:36 +02:00
</description>
</method>
2018-08-01 01:34:20 +02:00
<method name= "is_zero_approx" >
2021-07-30 15:28:05 +02:00
<return type= "bool" />
<argument index= "0" name= "s" type= "float" />
2018-08-01 01:34:20 +02:00
<description >
2019-11-30 21:08:50 +01:00
Returns [code]true[/code] if [code]s[/code] is zero or almost zero.
2020-07-22 03:21:41 +02:00
This method is faster than using [method is_equal_approx] with one value as zero.
2018-08-01 01:34:20 +02:00
</description>
</method>
2017-09-12 22:42:36 +02:00
<method name= "len" >
2021-07-30 15:28:05 +02:00
<return type= "int" />
<argument index= "0" name= "var" type= "Variant" />
2017-09-12 22:42:36 +02:00
<description >
2018-07-28 22:44:58 +02:00
Returns length of Variant [code]var[/code]. Length is the character count of String, element count of Array, size of Dictionary, etc.
[b]Note:[/b] Generates a fatal error if Variant can not provide a length.
2017-09-12 22:42:36 +02:00
[codeblock]
a = [1, 2, 3, 4]
2019-06-22 01:04:47 +02:00
len(a) # Returns 4
2017-09-12 22:42:36 +02:00
[/codeblock]
</description>
</method>
<method name= "lerp" >
2021-07-30 15:28:05 +02:00
<return type= "Variant" />
<argument index= "0" name= "from" type= "Variant" />
<argument index= "1" name= "to" type= "Variant" />
<argument index= "2" name= "weight" type= "float" />
2017-09-12 22:42:36 +02:00
<description >
2020-02-27 22:49:05 +01:00
Linearly interpolates between two values by a normalized value. This is the opposite of [method inverse_lerp].
2019-01-18 10:46:52 +01:00
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).
2017-09-13 08:18:51 +02:00
[codeblock]
2019-06-22 01:04:47 +02:00
lerp(0, 4, 0.75) # Returns 3.0
lerp(Vector2(1, 5), Vector2(3, 2), 0.5) # Returns Vector2(2, 3.5)
2017-09-13 08:18:51 +02:00
[/codeblock]
2017-09-12 22:42:36 +02:00
</description>
</method>
2019-07-14 06:30:45 +02:00
<method name= "lerp_angle" >
2021-07-30 15:28:05 +02:00
<return type= "float" />
<argument index= "0" name= "from" type= "float" />
<argument index= "1" name= "to" type= "float" />
<argument index= "2" name= "weight" type= "float" />
2019-07-14 06:30:45 +02:00
<description >
Linearly interpolates between two angles (in radians) by a normalized value.
2020-02-27 22:49:05 +01:00
Similar to [method lerp], but interpolates correctly when the angles wrap around [constant @GDScript.TAU].
2019-07-14 06:30:45 +02:00
[codeblock]
extends Sprite
var elapsed = 0.0
func _process(delta):
2019-09-28 02:21:58 +02:00
var min_angle = deg2rad(0.0)
var max_angle = deg2rad(90.0)
rotation = lerp_angle(min_angle, max_angle, elapsed)
elapsed += delta
2019-07-14 06:30:45 +02:00
[/codeblock]
</description>
</method>
2017-09-12 22:42:36 +02:00
<method name= "linear2db" >
2021-07-30 15:28:05 +02:00
<return type= "float" />
<argument index= "0" name= "nrg" type= "float" />
2017-09-12 22:42:36 +02:00
<description >
2020-02-27 22:49:46 +01:00
Converts from linear energy to decibels (audio). This can be used to implement volume sliders that behave as expected (since volume isn't linear). Example:
[codeblock]
# "Slider" refers to a node that inherits Range such as HSlider or VSlider.
# Its range must be configured to go from 0 to 1.
# Change the bus name if you'd like to change the volume of a specific bus only.
AudioServer.set_bus_volume_db(AudioServer.get_bus_index("Master"), linear2db($Slider.value))
[/codeblock]
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "load" >
2021-07-30 15:28:05 +02:00
<return type= "Resource" />
<argument index= "0" name= "path" type= "String" />
2017-09-12 22:42:36 +02:00
<description >
2020-06-28 20:51:46 +02:00
Loads a resource from the filesystem located at [code]path[/code]. The resource is loaded on the method call (unless it's referenced already elsewhere, e.g. in another script or in the scene), which might cause slight delay, especially when loading scenes. To avoid unnecessary delays when loading something multiple times, either store the resource in a variable or use [method preload].
[b]Note:[/b] Resource paths can be obtained by right-clicking on a resource in the FileSystem dock and choosing "Copy Path" or by dragging the file from the FileSystem dock into the script.
2017-09-12 22:42:36 +02:00
[codeblock]
2020-06-28 20:51:46 +02:00
# Load a scene called main located in the root of the project directory and cache it in a variable.
var main = load("res://main.tscn") # main will contain a PackedScene resource.
2017-09-12 22:42:36 +02:00
[/codeblock]
2019-12-11 21:14:58 +01:00
[b]Important:[/b] The path must be absolute, a local path will just return [code]null[/code].
2020-09-30 22:03:36 +02:00
This method is a simplified version of [method ResourceLoader.load], which can be used for more advanced scenarios.
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "log" >
2021-07-30 15:28:05 +02:00
<return type= "float" />
<argument index= "0" name= "s" type= "float" />
2017-09-12 22:42:36 +02:00
<description >
2018-07-28 22:44:58 +02:00
Natural logarithm. The amount of time needed to reach a certain level of continuous growth.
2019-06-22 01:04:47 +02:00
[b]Note:[/b] This is not the same as the "log" function on most calculators, which uses a base 10 logarithm.
2017-09-12 22:42:36 +02:00
[codeblock]
2019-06-22 01:04:47 +02:00
log(10) # Returns 2.302585
2017-09-12 22:42:36 +02:00
[/codeblock]
2020-07-25 16:11:23 +02:00
[b]Note:[/b] The logarithm of [code]0[/code] returns [code]-inf[/code], while negative values return [code]-nan[/code].
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "max" >
2021-07-30 15:28:05 +02:00
<return type= "float" />
<argument index= "0" name= "a" type= "float" />
<argument index= "1" name= "b" type= "float" />
2017-09-12 22:42:36 +02:00
<description >
Returns the maximum of two values.
[codeblock]
2019-06-22 01:04:47 +02:00
max(1, 2) # Returns 2
max(-3.99, -4) # Returns -3.99
2017-09-12 22:42:36 +02:00
[/codeblock]
</description>
</method>
<method name= "min" >
2021-07-30 15:28:05 +02:00
<return type= "float" />
<argument index= "0" name= "a" type= "float" />
<argument index= "1" name= "b" type= "float" />
2017-09-12 22:42:36 +02:00
<description >
Returns the minimum of two values.
[codeblock]
2019-06-22 01:04:47 +02:00
min(1, 2) # Returns 1
min(-3.99, -4) # Returns -4
2017-09-12 22:42:36 +02:00
[/codeblock]
</description>
</method>
2019-04-07 23:40:56 +02:00
<method name= "move_toward" >
2021-07-30 15:28:05 +02:00
<return type= "float" />
<argument index= "0" name= "from" type= "float" />
<argument index= "1" name= "to" type= "float" />
<argument index= "2" name= "delta" type= "float" />
2019-04-07 23:40:56 +02:00
<description >
Moves [code]from[/code] toward [code]to[/code] by the [code]delta[/code] value.
Use a negative [code]delta[/code] value to move away.
[codeblock]
2020-07-25 16:11:23 +02:00
move_toward(5, 10, 4) # Returns 9
2019-06-22 01:04:47 +02:00
move_toward(10, 5, 4) # Returns 6
2020-07-25 16:11:23 +02:00
move_toward(10, 5, -1.5) # Returns 11.5
2019-04-07 23:40:56 +02:00
[/codeblock]
</description>
</method>
2017-09-12 22:42:36 +02:00
<method name= "nearest_po2" >
2021-07-30 15:28:05 +02:00
<return type= "int" />
<argument index= "0" name= "value" type= "int" />
2017-09-12 22:42:36 +02:00
<description >
2020-07-25 16:11:23 +02:00
Returns the nearest equal or larger power of 2 for integer [code]value[/code].
In other words, returns the smallest value [code]a[/code] where [code]a = pow(2, n)[/code] such that [code]value < = a[/code] for some non-negative integer [code]n[/code].
2017-09-12 22:42:36 +02:00
[codeblock]
2019-06-22 01:04:47 +02:00
nearest_po2(3) # Returns 4
nearest_po2(4) # Returns 4
nearest_po2(5) # Returns 8
2020-07-25 16:11:23 +02:00
nearest_po2(0) # Returns 0 (this may not be what you expect)
nearest_po2(-1) # Returns 0 (this may not be what you expect)
2017-09-12 22:42:36 +02:00
[/codeblock]
2020-07-25 16:11:23 +02:00
[b]WARNING:[/b] Due to the way it is implemented, this function returns [code]0[/code] rather than [code]1[/code] for non-positive values of [code]value[/code] (in reality, 1 is the smallest integer power of 2).
2017-09-12 22:42:36 +02:00
</description>
</method>
2019-09-24 11:44:48 +02:00
<method name= "ord" >
2021-07-30 15:28:05 +02:00
<return type= "int" />
<argument index= "0" name= "char" type= "String" />
2019-09-24 11:44:48 +02:00
<description >
2019-12-15 04:10:29 +01:00
Returns an integer representing the Unicode code point of the given Unicode character [code]char[/code].
[codeblock]
a = ord("A") # a is 65
a = ord("a") # a is 97
a = ord("€") # a is 8364
[/codeblock]
This is the inverse of [method char].
2019-09-24 11:44:48 +02:00
</description>
</method>
2017-09-12 22:42:36 +02:00
<method name= "parse_json" >
2021-07-30 15:28:05 +02:00
<return type= "Variant" />
<argument index= "0" name= "json" type= "String" />
2017-09-12 22:42:36 +02:00
<description >
2020-07-31 09:53:04 +02:00
Parse JSON text to a Variant. (Use [method typeof] to check if the Variant's type is what you expect.)
[b]Note:[/b] The JSON specification does not define integer or float types, but only a [i]number[/i] type. Therefore, parsing a JSON text will convert all numerical values to [float] types.
[b]Note:[/b] JSON objects do not preserve key order like Godot dictionaries, thus, you should not rely on keys being in a certain order if a dictionary is constructed from JSON. In contrast, JSON arrays retain the order of their elements:
2017-09-12 22:42:36 +02:00
[codeblock]
2020-07-31 09:53:04 +02:00
var p = JSON.parse('["hello", "world", "!"]')
if typeof(p.result) == TYPE_ARRAY:
print(p.result[0]) # Prints "hello"
2017-09-12 22:42:36 +02:00
else:
2020-07-31 09:53:04 +02:00
push_error("Unexpected results.")
2017-09-12 22:42:36 +02:00
[/codeblock]
2020-07-31 09:53:04 +02:00
See also [JSON] for an alternative way to parse JSON text.
2017-09-12 22:42:36 +02:00
</description>
</method>
2017-10-13 01:15:45 +02:00
<method name= "polar2cartesian" >
2021-07-30 15:28:05 +02:00
<return type= "Vector2" />
<argument index= "0" name= "r" type= "float" />
<argument index= "1" name= "th" type= "float" />
2017-10-13 01:15:45 +02:00
<description >
2019-06-22 01:04:47 +02:00
Converts a 2D point expressed in the polar coordinate system (a distance from the origin [code]r[/code] and an angle [code]th[/code]) to the cartesian coordinate system (X and Y axis).
2017-10-13 01:15:45 +02:00
</description>
</method>
2019-07-22 12:24:14 +02:00
<method name= "posmod" >
2021-07-30 15:28:05 +02:00
<return type= "int" />
<argument index= "0" name= "a" type= "int" />
<argument index= "1" name= "b" type= "int" />
2019-07-22 12:24:14 +02:00
<description >
Returns the integer modulus of [code]a/b[/code] that wraps equally in positive and negative.
[codeblock]
2020-09-14 18:19:30 +02:00
for i in range(-3, 4):
2020-10-01 22:06:12 +02:00
print("%2d %2d %2d" % [i, i % 3, posmod(i, 3)])
2019-07-22 12:24:14 +02:00
[/codeblock]
Produces:
[codeblock]
2020-09-14 18:19:30 +02:00
-3 0 0
-2 -2 1
-1 -1 2
0 0 0
1 1 1
2 2 2
3 0 0
2019-07-22 12:24:14 +02:00
[/codeblock]
</description>
</method>
2017-09-12 22:42:36 +02:00
<method name= "pow" >
2021-07-30 15:28:05 +02:00
<return type= "float" />
<argument index= "0" name= "base" type= "float" />
<argument index= "1" name= "exp" type= "float" />
2017-09-12 22:42:36 +02:00
<description >
2020-12-13 23:53:30 +01:00
Returns the result of [code]base[/code] raised to the power of [code]exp[/code].
2017-09-12 22:42:36 +02:00
[codeblock]
2020-11-29 15:08:45 +01:00
pow(2, 5) # Returns 32.0
2017-09-12 22:42:36 +02:00
[/codeblock]
</description>
</method>
<method name= "preload" >
2021-07-30 15:28:05 +02:00
<return type= "Resource" />
<argument index= "0" name= "path" type= "String" />
2017-09-12 22:42:36 +02:00
<description >
2020-06-28 20:51:46 +02:00
Returns a [Resource] from the filesystem located at [code]path[/code]. The resource is loaded during script parsing, i.e. is loaded with the script and [method preload] effectively acts as a reference to that resource. Note that the method requires a constant path. If you want to load a resource from a dynamic/variable path, use [method load].
[b]Note:[/b] Resource paths can be obtained by right clicking on a resource in the Assets Panel and choosing "Copy Path" or by dragging the file from the FileSystem dock into the script.
2017-09-12 22:42:36 +02:00
[codeblock]
2020-06-28 20:51:46 +02:00
# Instance a scene.
var diamond = preload("res://diamond.tscn").instance()
2017-09-13 08:18:51 +02:00
[/codeblock]
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "print" qualifiers= "vararg" >
2021-07-30 15:28:05 +02:00
<return type= "void" />
2017-09-12 22:42:36 +02:00
<description >
2021-01-05 00:29:04 +01:00
Converts one or more arguments of any type to string in the best way possible and prints them to the console.
2017-09-12 22:42:36 +02:00
[codeblock]
2018-12-14 09:37:19 +01:00
a = [1, 2, 3]
2020-11-29 15:08:45 +01:00
print("a", "=", a) # Prints a=[1, 2, 3]
2017-09-12 22:42:36 +02:00
[/codeblock]
2020-09-23 23:24:58 +02:00
[b]Note:[/b] Consider using [method push_error] and [method push_warning] to print error and warning messages instead of [method print]. This distinguishes them from print messages used for debugging purposes, while also displaying a stack trace when an error or warning is printed.
2017-09-12 22:42:36 +02:00
</description>
</method>
2018-07-26 11:56:21 +02:00
<method name= "print_debug" qualifiers= "vararg" >
2021-07-30 15:28:05 +02:00
<return type= "void" />
2018-07-26 11:56:21 +02:00
<description >
2019-01-06 13:57:23 +01:00
Like [method print], but prints only when used in debug mode.
2018-07-26 11:56:21 +02:00
</description>
</method>
2017-09-12 22:42:36 +02:00
<method name= "print_stack" >
2021-07-30 15:28:05 +02:00
<return type= "void" />
2017-09-12 22:42:36 +02:00
<description >
2017-09-18 00:36:34 +02:00
Prints a stack track at code location, only works when running with debugger turned on.
2017-09-13 08:18:51 +02:00
Output in the console would look something like this:
[codeblock]
Frame 0 - res://test.gd:16 in function '_process'
[/codeblock]
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "printerr" qualifiers= "vararg" >
2021-07-30 15:28:05 +02:00
<return type= "void" />
2017-09-12 22:42:36 +02:00
<description >
2017-09-18 00:36:34 +02:00
Prints one or more arguments to strings in the best way possible to standard error line.
2017-09-13 08:18:51 +02:00
[codeblock]
printerr("prints to stderr")
[/codeblock]
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "printraw" qualifiers= "vararg" >
2021-07-30 15:28:05 +02:00
<return type= "void" />
2017-09-12 22:42:36 +02:00
<description >
2017-09-18 00:36:34 +02:00
Prints one or more arguments to strings in the best way possible to console. No newline is added at the end.
2017-09-13 08:18:51 +02:00
[codeblock]
printraw("A")
printraw("B")
2019-06-22 01:04:47 +02:00
# Prints AB
2017-09-13 08:18:51 +02:00
[/codeblock]
2019-11-02 09:53:46 +01:00
[b]Note:[/b] Due to limitations with Godot's built-in console, this only prints to the terminal. If you need to print in the editor, use another method, such as [method print].
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "prints" qualifiers= "vararg" >
2021-07-30 15:28:05 +02:00
<return type= "void" />
2017-09-12 22:42:36 +02:00
<description >
2017-09-18 00:36:34 +02:00
Prints one or more arguments to the console with a space between each argument.
2017-09-13 08:18:51 +02:00
[codeblock]
2019-06-22 01:04:47 +02:00
prints("A", "B", "C") # Prints A B C
2017-09-13 08:18:51 +02:00
[/codeblock]
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "printt" qualifiers= "vararg" >
2021-07-30 15:28:05 +02:00
<return type= "void" />
2017-09-12 22:42:36 +02:00
<description >
2017-09-18 00:36:34 +02:00
Prints one or more arguments to the console with a tab between each argument.
2017-09-13 08:18:51 +02:00
[codeblock]
2019-06-22 01:04:47 +02:00
printt("A", "B", "C") # Prints A B C
2017-09-13 08:18:51 +02:00
[/codeblock]
2017-09-12 22:42:36 +02:00
</description>
</method>
2018-11-10 14:21:34 +01:00
<method name= "push_error" >
2021-07-30 15:28:05 +02:00
<return type= "void" />
<argument index= "0" name= "message" type= "String" />
2018-11-10 14:21:34 +01:00
<description >
2018-12-07 04:11:07 +01:00
Pushes an error message to Godot's built-in debugger and to the OS terminal.
[codeblock]
2019-06-22 01:04:47 +02:00
push_error("test error") # Prints "test error" to debugger and terminal as error call
2018-12-07 04:11:07 +01:00
[/codeblock]
2020-09-23 23:24:58 +02:00
[b]Note:[/b] Errors printed this way will not pause project execution. To print an error message and pause project execution in debug builds, use [code]assert(false, "test error")[/code] instead.
2018-11-10 14:21:34 +01:00
</description>
</method>
<method name= "push_warning" >
2021-07-30 15:28:05 +02:00
<return type= "void" />
<argument index= "0" name= "message" type= "String" />
2018-11-10 14:21:34 +01:00
<description >
2018-12-07 04:11:07 +01:00
Pushes a warning message to Godot's built-in debugger and to the OS terminal.
[codeblock]
2019-06-22 01:04:47 +02:00
push_warning("test warning") # Prints "test warning" to debugger and terminal as warning call
2018-12-07 04:11:07 +01:00
[/codeblock]
2018-11-10 14:21:34 +01:00
</description>
</method>
2017-09-12 22:42:36 +02:00
<method name= "rad2deg" >
2021-07-30 15:28:05 +02:00
<return type= "float" />
<argument index= "0" name= "rad" type= "float" />
2017-09-12 22:42:36 +02:00
<description >
2020-07-22 03:21:41 +02:00
Converts an angle expressed in radians to degrees.
2017-09-13 08:18:51 +02:00
[codeblock]
2020-11-29 15:08:45 +01:00
rad2deg(0.523599) # Returns 30.0
2017-09-13 08:18:51 +02:00
[/codeblock]
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "rand_range" >
2021-07-30 15:28:05 +02:00
<return type= "float" />
<argument index= "0" name= "from" type= "float" />
<argument index= "1" name= "to" type= "float" />
2017-09-12 22:42:36 +02:00
<description >
2019-02-18 09:45:10 +01:00
Random range, any floating point value between [code]from[/code] and [code]to[/code].
2017-09-13 08:18:51 +02:00
[codeblock]
2019-06-22 01:04:47 +02:00
prints(rand_range(0, 1), rand_range(0, 1)) # Prints e.g. 0.135591 0.405263
2017-09-13 08:18:51 +02:00
[/codeblock]
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "rand_seed" >
2021-07-30 15:28:05 +02:00
<return type= "Array" />
<argument index= "0" name= "seed" type= "int" />
2017-09-12 22:42:36 +02:00
<description >
2017-09-18 00:36:34 +02:00
Random from seed: pass a [code]seed[/code], and an array with both number and new seed is returned. "Seed" here refers to the internal state of the pseudo random number generator. The internal state of the current implementation is 64 bits.
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "randf" >
2021-07-30 15:28:05 +02:00
<return type= "float" />
2017-09-12 22:42:36 +02:00
<description >
2019-02-18 09:45:10 +01:00
Returns a random floating point value on the interval [code][0, 1][/code].
2017-09-13 08:18:51 +02:00
[codeblock]
2019-06-22 01:04:47 +02:00
randf() # Returns e.g. 0.375671
2017-09-13 08:18:51 +02:00
[/codeblock]
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "randi" >
2021-07-30 15:28:05 +02:00
<return type= "int" />
2017-09-12 22:42:36 +02:00
<description >
2021-03-18 12:04:28 +01:00
Returns a random unsigned 32-bit integer. Use remainder to obtain a random value in the interval [code][0, N - 1][/code] (where N is smaller than 2^32).
2017-09-13 08:18:51 +02:00
[codeblock]
2019-06-22 01:04:47 +02:00
randi() # Returns random integer between 0 and 2^32 - 1
randi() % 20 # Returns random integer between 0 and 19
randi() % 100 # Returns random integer between 0 and 99
randi() % 100 + 1 # Returns random integer between 1 and 100
2017-09-13 08:18:51 +02:00
[/codeblock]
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "randomize" >
2021-07-30 15:28:05 +02:00
<return type= "void" />
2017-09-12 22:42:36 +02:00
<description >
2017-09-18 00:36:34 +02:00
Randomizes the seed (or the internal state) of the random number generator. Current implementation reseeds using a number based on time.
2017-09-13 08:18:51 +02:00
[codeblock]
func _ready():
randomize()
[/codeblock]
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "range" qualifiers= "vararg" >
2021-07-30 15:28:05 +02:00
<return type= "Array" />
2017-09-12 22:42:36 +02:00
<description >
2017-09-18 00:36:34 +02:00
Returns an array with the given range. Range can be 1 argument N (0 to N-1), two arguments (initial, final-1) or three arguments (initial, final-1, increment).
2017-09-13 08:18:51 +02:00
[codeblock]
2020-09-14 18:19:30 +02:00
print(range(4))
print(range(2, 5))
print(range(0, 6, 2))
2017-09-13 08:18:51 +02:00
[/codeblock]
Output:
[codeblock]
2020-09-14 18:19:30 +02:00
[0, 1, 2, 3]
[2, 3, 4]
[0, 2, 4]
2017-09-13 08:18:51 +02:00
[/codeblock]
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "range_lerp" >
2021-07-30 15:28:05 +02:00
<return type= "float" />
<argument index= "0" name= "value" type= "float" />
<argument index= "1" name= "istart" type= "float" />
<argument index= "2" name= "istop" type= "float" />
<argument index= "3" name= "ostart" type= "float" />
<argument index= "4" name= "ostop" type= "float" />
2017-09-12 22:42:36 +02:00
<description >
2017-09-18 00:36:34 +02:00
Maps a [code]value[/code] from range [code][istart, istop][/code] to [code][ostart, ostop][/code].
2017-09-12 22:42:36 +02:00
[codeblock]
2019-06-22 01:04:47 +02:00
range_lerp(75, 0, 100, -1, 1) # Returns 0.5
2017-09-12 22:42:36 +02:00
[/codeblock]
</description>
</method>
<method name= "round" >
2021-07-30 15:28:05 +02:00
<return type= "float" />
<argument index= "0" name= "s" type= "float" />
2017-09-12 22:42:36 +02:00
<description >
2020-07-22 03:21:41 +02:00
Rounds [code]s[/code] to the nearest whole number, with halfway cases rounded away from zero.
2017-09-13 08:18:51 +02:00
[codeblock]
2020-11-29 15:08:45 +01:00
a = round(2.49) # a is 2.0
a = round(2.5) # a is 3.0
a = round(2.51) # a is 3.0
2017-09-13 08:18:51 +02:00
[/codeblock]
2020-11-29 15:08:45 +01:00
See also [method floor], [method ceil], [method stepify], and [int].
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "seed" >
2021-07-30 15:28:05 +02:00
<return type= "void" />
<argument index= "0" name= "seed" type= "int" />
2017-09-12 22:42:36 +02:00
<description >
2017-09-18 00:36:34 +02:00
Sets seed for the random number generator.
2017-09-13 08:18:51 +02:00
[codeblock]
my_seed = "Godot Rocks"
seed(my_seed.hash())
[/codeblock]
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "sign" >
2021-07-30 15:28:05 +02:00
<return type= "float" />
<argument index= "0" name= "s" type= "float" />
2017-09-12 22:42:36 +02:00
<description >
2017-12-29 13:11:27 +01:00
Returns the sign of [code]s[/code]: -1 or 1. Returns 0 if [code]s[/code] is 0.
2017-09-13 08:18:51 +02:00
[codeblock]
2019-06-22 01:04:47 +02:00
sign(-6) # Returns -1
sign(0) # Returns 0
sign(6) # Returns 1
2017-09-13 08:18:51 +02:00
[/codeblock]
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "sin" >
2021-07-30 15:28:05 +02:00
<return type= "float" />
<argument index= "0" name= "s" type= "float" />
2017-09-12 22:42:36 +02:00
<description >
2017-09-18 00:36:34 +02:00
Returns the sine of angle [code]s[/code] in radians.
2017-09-13 08:18:51 +02:00
[codeblock]
2019-06-22 01:04:47 +02:00
sin(0.523599) # Returns 0.5
2017-09-13 08:18:51 +02:00
[/codeblock]
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "sinh" >
2021-07-30 15:28:05 +02:00
<return type= "float" />
<argument index= "0" name= "s" type= "float" />
2017-09-12 22:42:36 +02:00
<description >
2017-09-18 00:36:34 +02:00
Returns the hyperbolic sine of [code]s[/code].
2017-09-13 08:18:51 +02:00
[codeblock]
2019-06-22 01:04:47 +02:00
a = log(2.0) # Returns 0.693147
sinh(a) # Returns 0.75
2017-09-13 08:18:51 +02:00
[/codeblock]
2017-09-12 22:42:36 +02:00
</description>
</method>
2019-03-19 12:39:43 +01:00
<method name= "smoothstep" >
2021-07-30 15:28:05 +02:00
<return type= "float" />
<argument index= "0" name= "from" type= "float" />
<argument index= "1" name= "to" type= "float" />
<argument index= "2" name= "s" type= "float" />
2019-03-19 12:39:43 +01:00
<description >
2020-07-25 16:11:23 +02:00
Returns the result of smoothly interpolating the value of [code]s[/code] between [code]0[/code] and [code]1[/code], based on the where [code]s[/code] lies with respect to the edges [code]from[/code] and [code]to[/code].
The return value is [code]0[/code] if [code]s < = from[/code], and [code]1[/code] if [code]s > = to[/code]. If [code]s[/code] lies between [code]from[/code] and [code]to[/code], the returned value follows an S-shaped curve that maps [code]s[/code] between [code]0[/code] and [code]1[/code].
2021-02-12 21:42:58 +01:00
This S-shaped curve is the cubic Hermite interpolator, given by [code]f(y) = 3*y^2 - 2*y^3[/code] where [code]y = (x-from) / (to-from)[/code].
2019-03-19 12:39:43 +01:00
[codeblock]
2020-11-29 15:08:45 +01:00
smoothstep(0, 2, -5.0) # Returns 0.0
2020-07-25 16:11:23 +02:00
smoothstep(0, 2, 0.5) # Returns 0.15625
smoothstep(0, 2, 1.0) # Returns 0.5
smoothstep(0, 2, 2.0) # Returns 1.0
2019-03-19 12:39:43 +01:00
[/codeblock]
</description>
</method>
2017-09-12 22:42:36 +02:00
<method name= "sqrt" >
2021-07-30 15:28:05 +02:00
<return type= "float" />
<argument index= "0" name= "s" type= "float" />
2017-09-12 22:42:36 +02:00
<description >
2020-07-22 03:21:41 +02:00
Returns the square root of [code]s[/code], where [code]s[/code] is a non-negative number.
2017-09-13 08:18:51 +02:00
[codeblock]
2019-06-22 01:04:47 +02:00
sqrt(9) # Returns 3
2017-09-13 08:18:51 +02:00
[/codeblock]
2021-04-07 11:52:44 +02:00
[b]Note:[/b] Negative values of [code]s[/code] return NaN. If you need negative inputs, use [code]System.Numerics.Complex[/code] in C#.
2017-09-12 22:42:36 +02:00
</description>
</method>
2018-10-26 02:20:20 +02:00
<method name= "step_decimals" >
2021-07-30 15:28:05 +02:00
<return type= "int" />
<argument index= "0" name= "step" type= "float" />
2018-10-26 02:20:20 +02:00
<description >
2019-07-23 17:27:55 +02:00
Returns the position of the first non-zero digit, after the decimal point. Note that the maximum return value is 10, which is a design decision in the implementation.
2018-10-26 02:20:20 +02:00
[codeblock]
2020-11-29 15:08:45 +01:00
n = step_decimals(5) # n is 0
n = step_decimals(1.0005) # n is 4
n = step_decimals(0.000000005) # n is 9
2018-10-26 02:20:20 +02:00
[/codeblock]
</description>
</method>
2017-09-12 22:42:36 +02:00
<method name= "stepify" >
2021-07-30 15:28:05 +02:00
<return type= "float" />
<argument index= "0" name= "s" type= "float" />
<argument index= "1" name= "step" type= "float" />
2017-09-12 22:42:36 +02:00
<description >
2019-08-29 14:03:18 +02:00
Snaps float value [code]s[/code] to a given [code]step[/code]. This can also be used to round a floating point number to an arbitrary number of decimals.
[codeblock]
2020-11-29 15:08:45 +01:00
stepify(100, 32) # Returns 96.0
2019-08-29 14:03:18 +02:00
stepify(3.14159, 0.01) # Returns 3.14
2019-08-29 15:33:52 +02:00
[/codeblock]
2020-11-29 15:08:45 +01:00
See also [method ceil], [method floor], [method round], and [int].
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "str" qualifiers= "vararg" >
2021-07-30 15:28:05 +02:00
<return type= "String" />
2017-09-12 22:42:36 +02:00
<description >
2021-01-05 00:29:04 +01:00
Converts one or more arguments of any type to string in the best way possible.
2017-09-13 08:18:51 +02:00
[codeblock]
var a = [10, 20, 30]
var b = str(a);
2019-06-22 01:04:47 +02:00
len(a) # Returns 3
len(b) # Returns 12
2017-09-13 08:18:51 +02:00
[/codeblock]
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "str2var" >
2021-07-30 15:28:05 +02:00
<return type= "Variant" />
<argument index= "0" name= "string" type= "String" />
2017-09-12 22:42:36 +02:00
<description >
2017-09-18 00:36:34 +02:00
Converts a formatted string that was returned by [method var2str] to the original value.
2017-09-13 08:18:51 +02:00
[codeblock]
a = '{ "a": 1, "b": 2 }'
b = str2var(a)
2019-06-22 01:04:47 +02:00
print(b["a"]) # Prints 1
2017-09-13 08:18:51 +02:00
[/codeblock]
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "tan" >
2021-07-30 15:28:05 +02:00
<return type= "float" />
<argument index= "0" name= "s" type= "float" />
2017-09-12 22:42:36 +02:00
<description >
2017-09-18 00:36:34 +02:00
Returns the tangent of angle [code]s[/code] in radians.
2017-09-13 08:18:51 +02:00
[codeblock]
2019-06-22 01:04:47 +02:00
tan(deg2rad(45)) # Returns 1
2017-09-13 08:18:51 +02:00
[/codeblock]
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "tanh" >
2021-07-30 15:28:05 +02:00
<return type= "float" />
<argument index= "0" name= "s" type= "float" />
2017-09-12 22:42:36 +02:00
<description >
2017-09-18 00:36:34 +02:00
Returns the hyperbolic tangent of [code]s[/code].
2017-09-13 08:18:51 +02:00
[codeblock]
2020-11-29 15:08:45 +01:00
a = log(2.0) # a is 0.693147
b = tanh(a) # b is 0.6
2017-09-13 08:18:51 +02:00
[/codeblock]
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "to_json" >
2021-07-30 15:28:05 +02:00
<return type= "String" />
<argument index= "0" name= "var" type= "Variant" />
2017-09-12 22:42:36 +02:00
<description >
2020-07-31 09:53:04 +02:00
Converts a [Variant] [code]var[/code] to JSON text and return the result. Useful for serializing data to store or send over the network.
2017-09-13 08:18:51 +02:00
[codeblock]
2020-07-31 09:53:04 +02:00
# Both numbers below are integers.
2019-06-22 01:04:47 +02:00
a = { "a": 1, "b": 2 }
2017-09-13 08:18:51 +02:00
b = to_json(a)
print(b) # {"a":1, "b":2}
2020-07-31 09:53:04 +02:00
# Both numbers above are floats, even if they display without any decimal places.
2017-09-13 08:18:51 +02:00
[/codeblock]
2020-07-31 09:53:04 +02:00
[b]Note:[/b] The JSON specification does not define integer or float types, but only a [i]number[/i] type. Therefore, converting a [Variant] to JSON text will convert all numerical values to [float] types.
See also [JSON] for an alternative way to convert a [Variant] to JSON text.
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "type_exists" >
2021-07-30 15:28:05 +02:00
<return type= "bool" />
<argument index= "0" name= "type" type= "String" />
2017-09-12 22:42:36 +02:00
<description >
2017-09-18 00:36:34 +02:00
Returns whether the given class exists in [ClassDB].
2017-09-12 22:42:36 +02:00
[codeblock]
2019-06-22 01:04:47 +02:00
type_exists("Sprite") # Returns true
type_exists("Variant") # Returns false
2017-09-12 22:42:36 +02:00
[/codeblock]
</description>
</method>
<method name= "typeof" >
2021-07-30 15:28:05 +02:00
<return type= "int" />
<argument index= "0" name= "what" type= "Variant" />
2017-09-12 22:42:36 +02:00
<description >
2019-12-06 23:09:20 +01:00
Returns the internal type of the given Variant object, using the [enum Variant.Type] values.
2017-09-13 08:18:51 +02:00
[codeblock]
p = parse_json('["a", "b", "c"]')
if typeof(p) == TYPE_ARRAY:
2019-06-22 01:04:47 +02:00
print(p[0]) # Prints a
2017-09-13 08:18:51 +02:00
else:
print("unexpected results")
[/codeblock]
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "validate_json" >
2021-07-30 15:28:05 +02:00
<return type= "String" />
<argument index= "0" name= "json" type= "String" />
2017-09-12 22:42:36 +02:00
<description >
2019-12-06 23:09:20 +01:00
Checks that [code]json[/code] is valid JSON data. Returns an empty string if valid, or an error message otherwise.
2017-09-13 08:18:51 +02:00
[codeblock]
j = to_json([1, 2, 3])
v = validate_json(j)
if not v:
2020-07-31 09:53:04 +02:00
print("Valid JSON.")
2017-09-13 08:18:51 +02:00
else:
2020-07-31 09:53:04 +02:00
push_error("Invalid JSON: " + v)
2017-09-13 08:18:51 +02:00
[/codeblock]
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "var2bytes" >
2021-07-30 15:28:05 +02:00
<return type= "PoolByteArray" />
<argument index= "0" name= "var" type= "Variant" />
<argument index= "1" name= "full_objects" type= "bool" default= "false" />
2017-09-12 22:42:36 +02:00
<description >
2019-03-26 16:52:42 +01:00
Encodes a variable value to a byte array. When [code]full_objects[/code] is [code]true[/code] encoding objects is allowed (and can potentially include code).
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "var2str" >
2021-07-30 15:28:05 +02:00
<return type= "String" />
<argument index= "0" name= "var" type= "Variant" />
2017-09-12 22:42:36 +02:00
<description >
2017-09-18 00:36:34 +02:00
Converts a Variant [code]var[/code] to a formatted string that can later be parsed using [method str2var].
2017-09-13 08:18:51 +02:00
[codeblock]
2019-06-22 01:04:47 +02:00
a = { "a": 1, "b": 2 }
2017-09-13 08:18:51 +02:00
print(var2str(a))
[/codeblock]
prints
[codeblock]
{
"a": 1,
"b": 2
}
[/codeblock]
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "weakref" >
2021-07-30 15:28:05 +02:00
<return type= "WeakRef" />
<argument index= "0" name= "obj" type= "Object" />
2017-09-12 22:42:36 +02:00
<description >
2017-09-18 00:36:34 +02:00
Returns a weak reference to an object.
2017-09-12 22:42:36 +02:00
A weak reference to an object is not enough to keep the object alive: when the only remaining references to a referent are weak references, garbage collection is free to destroy the referent and reuse its memory for something else. However, until the object is actually destroyed the weak reference may return the object even if there are no strong references to it.
</description>
</method>
2017-11-04 17:09:37 +01:00
<method name= "wrapf" >
2021-07-30 15:28:05 +02:00
<return type= "float" />
<argument index= "0" name= "value" type= "float" />
<argument index= "1" name= "min" type= "float" />
<argument index= "2" name= "max" type= "float" />
2017-11-04 17:09:37 +01:00
<description >
Wraps float [code]value[/code] between [code]min[/code] and [code]max[/code].
Usable for creating loop-alike behavior or infinite surfaces.
[codeblock]
2020-07-22 03:21:41 +02:00
# Infinite loop between 5.0 and 9.9
value = wrapf(value + 0.1, 5.0, 10.0)
2017-11-04 17:09:37 +01:00
[/codeblock]
2019-06-25 08:36:10 +02:00
[codeblock]
2019-06-22 01:04:47 +02:00
# Infinite rotation (in radians)
2019-06-25 08:36:10 +02:00
angle = wrapf(angle + 0.1, 0.0, TAU)
[/codeblock]
[codeblock]
2019-06-22 01:04:47 +02:00
# Infinite rotation (in radians)
2019-06-25 08:36:10 +02:00
angle = wrapf(angle + 0.1, -PI, PI)
[/codeblock]
2020-07-22 03:21:41 +02:00
[b]Note:[/b] If [code]min[/code] is [code]0[/code], this is equivalent to [method fposmod], so prefer using that instead.
[code]wrapf[/code] is more flexible than using the [method fposmod] approach by giving the user control over the minimum value.
2017-11-04 17:09:37 +01:00
</description>
</method>
<method name= "wrapi" >
2021-07-30 15:28:05 +02:00
<return type= "int" />
<argument index= "0" name= "value" type= "int" />
<argument index= "1" name= "min" type= "int" />
<argument index= "2" name= "max" type= "int" />
2017-11-04 17:09:37 +01:00
<description >
Wraps integer [code]value[/code] between [code]min[/code] and [code]max[/code].
Usable for creating loop-alike behavior or infinite surfaces.
[codeblock]
2020-07-22 03:21:41 +02:00
# Infinite loop between 5 and 9
frame = wrapi(frame + 1, 5, 10)
2017-11-04 17:09:37 +01:00
[/codeblock]
2019-06-25 08:36:10 +02:00
[codeblock]
# result is -2
var result = wrapi(-6, -5, -1)
[/codeblock]
2020-07-22 03:21:41 +02:00
[b]Note:[/b] If [code]min[/code] is [code]0[/code], this is equivalent to [method posmod], so prefer using that instead.
[code]wrapi[/code] is more flexible than using the [method posmod] approach by giving the user control over the minimum value.
2017-11-04 17:09:37 +01:00
</description>
</method>
2017-09-12 22:42:36 +02:00
<method name= "yield" >
2021-07-30 15:28:05 +02:00
<return type= "GDScriptFunctionState" />
<argument index= "0" name= "object" type= "Object" default= "null" />
<argument index= "1" name= "signal" type= "String" default= """" />
2017-09-12 22:42:36 +02:00
<description >
2018-07-02 21:25:51 +02:00
Stops the function execution and returns the current suspended state to the calling function.
From the caller, call [method GDScriptFunctionState.resume] on the state to resume execution. This invalidates the state. Within the resumed function, [code]yield()[/code] returns whatever was passed to the [code]resume()[/code] function call.
If passed an object and a signal, the execution is resumed when the object emits the given signal. In this case, [code]yield()[/code] returns the argument passed to [code]emit_signal()[/code] if the signal takes only one argument, or an array containing all the arguments passed to [code]emit_signal()[/code] if the signal takes multiple arguments.
2019-11-25 08:42:31 +01:00
You can also use [code]yield[/code] to wait for a function to finish:
[codeblock]
2019-11-26 19:09:28 +01:00
func _ready():
2019-12-11 18:54:15 +01:00
yield(countdown(), "completed") # waiting for the countdown() function to complete
print('Ready')
2019-11-25 08:42:31 +01:00
2019-12-11 18:54:15 +01:00
func countdown():
yield(get_tree(), "idle_frame") # returns a GDScriptFunctionState object to _ready()
print(3)
yield(get_tree().create_timer(1.0), "timeout")
print(2)
yield(get_tree().create_timer(1.0), "timeout")
print(1)
yield(get_tree().create_timer(1.0), "timeout")
2019-11-26 19:09:28 +01:00
2019-11-25 08:42:31 +01:00
# prints:
2019-12-11 18:54:15 +01:00
# 3
# 2
# 1
# Ready
2019-11-25 08:42:31 +01:00
[/codeblock]
When yielding on a function, the [code]completed[/code] signal will be emitted automatically when the function returns. It can, therefore, be used as the [code]signal[/code] parameter of the [code]yield[/code] method to resume.
2019-12-11 18:54:15 +01:00
In order to yield on a function, the resulting function should also return a [code]GDScriptFunctionState[/code]. Notice [code]yield(get_tree(), "idle_frame")[/code] from the above example.
2017-09-12 22:42:36 +02:00
</description>
</method>
</methods>
<constants >
2017-11-24 23:16:30 +01:00
<constant name= "PI" value= "3.141593" >
2020-07-22 03:21:41 +02:00
Constant that represents how many times the diameter of a circle fits around its perimeter. This is equivalent to [code]TAU / 2[/code].
2017-11-04 10:34:27 +01:00
</constant>
2017-11-24 23:16:30 +01:00
<constant name= "TAU" value= "6.283185" >
2021-07-22 08:36:14 +02:00
The circle constant, the circumference of the unit circle in radians. This is equivalent to [code]PI * 2[/code], or 360 degrees in rotations.
2017-09-12 22:42:36 +02:00
</constant>
2017-11-24 23:16:30 +01:00
<constant name= "INF" value= "inf" >
2021-07-22 08:36:14 +02:00
Positive floating-point infinity. This is the result of floating-point division when the divisor is [code]0.0[/code]. For negative infinity, use [code]-INF[/code]. Dividing by [code]-0.0[/code] will result in negative infinity if the numerator is positive, so dividing by [code]0.0[/code] is not the same as dividing by [code]-0.0[/code] (despite [code]0.0 == -0.0[/code] returning [code]true[/code]).
[b]Note:[/b] Numeric infinity is only a concept with floating-point numbers, and has no equivalent for integers. Dividing an integer number by [code]0[/code] will not result in [constant INF] and will result in a run-time error instead.
2017-09-12 22:42:36 +02:00
</constant>
2018-06-13 14:42:55 +02:00
<constant name= "NAN" value= "nan" >
2021-07-22 08:36:14 +02:00
"Not a Number", an invalid floating-point value. [constant NAN] has special properties, including that it is not equal to itself ([code]NAN == NAN[/code] returns [code]false[/code]). It is output by some invalid operations, such as dividing floating-point [code]0.0[/code] by [code]0.0[/code].
[b]Note:[/b] "Not a Number" is only a concept with floating-point numbers, and has no equivalent for integers. Dividing an integer [code]0[/code] by [code]0[/code] will not result in [constant NAN] and will result in a run-time error instead.
2017-09-12 22:42:36 +02:00
</constant>
</constants>
</class>