2017-09-12 20:42:36 +00:00
<?xml version="1.0" encoding="UTF-8" ?>
2019-04-01 10:33:56 +00:00
<class name= "@GDScript" category= "Core" version= "3.2" >
2017-09-12 20:42:36 +00:00
<brief_description >
Built-in GDScript functions.
</brief_description>
<description >
2018-06-18 02:25:27 +00: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 20:42:36 +00:00
</description>
<tutorials >
</tutorials>
<methods >
<method name= "Color8" >
<return type= "Color" >
</return>
<argument index= "0" name= "r8" type= "int" >
</argument>
<argument index= "1" name= "g8" type= "int" >
</argument>
<argument index= "2" name= "b8" type= "int" >
</argument>
2018-02-19 09:47:16 +00:00
<argument index= "3" name= "a8" type= "int" default= "255" >
2017-09-12 20:42:36 +00:00
</argument>
<description >
2017-09-17 22:36:34 +00:00
Returns a 32 bit color with red, green, blue and alpha channels. Each channel has 8 bits of information ranging from 0 to 255.
[code]r8[/code] red channel
[code]g8[/code] green channel
[code]b8[/code] blue channel
[code]a8[/code] alpha channel
2017-09-12 20:42:36 +00:00
[codeblock]
red = Color8(255, 0, 0)
[/codeblock]
</description>
</method>
<method name= "ColorN" >
<return type= "Color" >
</return>
<argument index= "0" name= "name" type= "String" >
</argument>
2018-02-19 09:47:16 +00:00
<argument index= "1" name= "alpha" type= "float" default= "1.0" >
2017-09-12 20:42:36 +00:00
</argument>
<description >
2018-01-07 18:43:50 +00:00
Returns a color according to the standardised [code]name[/code] with [code]alpha[/code] ranging from 0 to 1.
2017-09-12 20:42:36 +00:00
[codeblock]
2018-01-07 18:43:50 +00:00
red = ColorN("red", 1)
2017-09-12 20:42:36 +00:00
[/codeblock]
2018-01-07 18:43:50 +00:00
Supported color names:
"aliceblue", "antiquewhite", "aqua", "aquamarine", "azure", "beige", "bisque", "black", "blanchedalmond", "blue", "blueviolet", "brown", "burlywood", "cadetblue", "chartreuse", "chocolate", "coral", "cornflower", "cornsilk", "crimson", "cyan", "darkblue", "darkcyan", "darkgoldenrod", "darkgray", "darkgreen", "darkkhaki", "darkmagenta", "darkolivegreen", "darkorange", "darkorchid", "darkred", "darksalmon", "darkseagreen", "darkslateblue", "darkslategray", "darkturquoise", "darkviolet", "deeppink", "deepskyblue", "dimgray", "dodgerblue", "firebrick", "floralwhite", "forestgreen", "fuchsia", "gainsboro", "ghostwhite", "gold", "goldenrod", "gray", "webgray", "green", "webgreen", "greenyellow", "honeydew", "hotpink", "indianred", "indigo", "ivory", "khaki", "lavender", "lavenderblush", "lawngreen", "lemonchiffon", "lightblue", "lightcoral", "lightcyan", "lightgoldenrod", "lightgray", "lightgreen", "lightpink", "lightsalmon", "lightseagreen", "lightskyblue", "lightslategray", "lightsteelblue", "lightyellow", "lime", "limegreen", "linen", "magenta", "maroon", "webmaroon", "mediumaquamarine", "mediumblue", "mediumorchid", "mediumpurple", "mediumseagreen", "mediumslateblue", "mediumspringgreen", "mediumturquoise", "mediumvioletred", "midnightblue", "mintcream", "mistyrose", "moccasin", "navajowhite", "navyblue", "oldlace", "olive", "olivedrab", "orange", "orangered", "orchid", "palegoldenrod", "palegreen", "paleturquoise", "palevioletred", "papayawhip", "peachpuff", "peru", "pink", "plum", "powderblue", "purple", "webpurple", "rebeccapurple", "red", "rosybrown", "royalblue", "saddlebrown", "salmon", "sandybrown", "seagreen", "seashell", "sienna", "silver", "skyblue", "slateblue", "slategray", "snow", "springgreen", "steelblue", "tan", "teal", "thistle", "tomato", "turquoise", "violet", "wheat", "white", "whitesmoke", "yellow", "yellowgreen".
2017-09-12 20:42:36 +00:00
</description>
</method>
<method name= "abs" >
<return type= "float" >
</return>
<argument index= "0" name= "s" type= "float" >
</argument>
<description >
2018-09-22 21:50:45 +00:00
Returns the absolute value of parameter [code]s[/code] (i.e. unsigned value, works for integer and float).
2017-09-12 20:42:36 +00:00
[codeblock]
# a is 1
a = abs(-1)
[/codeblock]
</description>
</method>
<method name= "acos" >
<return type= "float" >
</return>
<argument index= "0" name= "s" type= "float" >
</argument>
<description >
2017-09-17 22:36:34 +00:00
Returns the arc cosine of [code]s[/code] in radians. Use to get the angle of cosine [code]s[/code].
2017-09-12 20:42:36 +00:00
[codeblock]
# c is 0.523599 or 30 degrees if converted with rad2deg(s)
c = acos(0.866025)
[/codeblock]
</description>
</method>
<method name= "asin" >
<return type= "float" >
</return>
<argument index= "0" name= "s" type= "float" >
</argument>
<description >
2017-09-17 22:36:34 +00:00
Returns the arc sine of [code]s[/code] in radians. Use to get the angle of sine [code]s[/code].
2017-09-12 20:42:36 +00:00
[codeblock]
# s is 0.523599 or 30 degrees if converted with rad2deg(s)
2017-09-13 06:18:51 +00:00
s = asin(0.5)
2017-09-12 20:42:36 +00:00
[/codeblock]
</description>
</method>
<method name= "assert" >
<return type= "void" >
</return>
<argument index= "0" name= "condition" type= "bool" >
</argument>
<description >
2019-06-03 10:27:37 +00:00
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.
2017-09-13 06:18:51 +00:00
[codeblock]
2019-06-03 10:27:37 +00:00
# Imagine we always want speed to be between 0 and 20
2017-09-13 06:18:51 +00:00
speed = -10
2019-06-03 10:27:37 +00:00
assert(speed < 20) # True, the program will continue
assert(speed > = 0) # False, the program will stop
assert(speed > = 0 & & speed < 20) # You can also combine the two conditional statements in one check
2017-09-13 06:18:51 +00:00
[/codeblock]
2017-09-12 20:42:36 +00:00
</description>
</method>
<method name= "atan" >
<return type= "float" >
</return>
<argument index= "0" name= "s" type= "float" >
</argument>
<description >
2017-09-17 22:36:34 +00: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].
2017-09-13 06:18:51 +00:00
The method cannot know in which quadrant the angle should fall. See [method atan2] if you always want an exact angle.
[codeblock]
a = atan(0.5) # a is 0.463648
[/codeblock]
2017-09-12 20:42:36 +00:00
</description>
</method>
<method name= "atan2" >
<return type= "float" >
</return>
2018-09-21 07:33:05 +00:00
<argument index= "0" name= "y" type= "float" >
2017-09-12 20:42:36 +00:00
</argument>
2018-09-21 07:33:05 +00:00
<argument index= "1" name= "x" type= "float" >
2017-09-12 20:42:36 +00:00
</argument>
<description >
2017-09-17 22:36:34 +00: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.
2017-09-12 20:42:36 +00:00
[codeblock]
2019-03-27 16:13:37 +00:00
a = atan2(0, -1) # a is 3.141593
2017-09-12 20:42:36 +00:00
[/codeblock]
</description>
</method>
<method name= "bytes2var" >
<return type= "Variant" >
</return>
<argument index= "0" name= "bytes" type= "PoolByteArray" >
</argument>
2019-03-26 15:52:42 +00:00
<argument index= "1" name= "allow_objects" type= "bool" default= "false" >
</argument>
2017-09-12 20:42:36 +00:00
<description >
2019-03-26 15:52:42 +00: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 20:42:36 +00:00
</description>
</method>
2017-10-12 23:15:45 +00:00
<method name= "cartesian2polar" >
<return type= "Vector2" >
</return>
<argument index= "0" name= "x" type= "float" >
</argument>
<argument index= "1" name= "y" type= "float" >
</argument>
<description >
2019-06-21 23:04:47 +00: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-12 23:15:45 +00:00
</description>
</method>
2017-09-12 20:42:36 +00:00
<method name= "ceil" >
<return type= "float" >
</return>
<argument index= "0" name= "s" type= "float" >
</argument>
<description >
2017-09-17 22:36:34 +00:00
Rounds [code]s[/code] upward, returning the smallest integral value that is not less than [code]s[/code].
2017-09-12 20:42:36 +00:00
[codeblock]
2017-09-13 06:18:51 +00:00
i = ceil(1.45) # i is 2
i = ceil(1.001) # i is 2
2017-09-12 20:42:36 +00:00
[/codeblock]
</description>
</method>
<method name= "char" >
<return type= "String" >
</return>
<argument index= "0" name= "ascii" type= "int" >
</argument>
<description >
2017-09-17 22:36:34 +00:00
Returns a character as a String of the given ASCII code.
2017-09-12 20:42:36 +00:00
[codeblock]
2019-06-21 23:04:47 +00:00
a = char(65) # a is "A"
a = char(65 + 32) # a is "a"
2017-09-12 20:42:36 +00:00
[/codeblock]
</description>
</method>
<method name= "clamp" >
<return type= "float" >
</return>
2018-01-16 16:31:10 +00:00
<argument index= "0" name= "value" type= "float" >
2017-09-12 20:42:36 +00:00
</argument>
<argument index= "1" name= "min" type= "float" >
</argument>
<argument index= "2" name= "max" type= "float" >
</argument>
<description >
2018-01-17 10:28:59 +00: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 20:42:36 +00:00
[codeblock]
speed = 1000
# a is 20
a = clamp(speed, 1, 20)
speed = -10
# a is 1
a = clamp(speed, 1, 20)
[/codeblock]
</description>
</method>
<method name= "convert" >
2018-07-26 09:56:21 +00:00
<return type= "Variant" >
2017-09-12 20:42:36 +00:00
</return>
<argument index= "0" name= "what" type= "Variant" >
</argument>
<argument index= "1" name= "type" type= "int" >
</argument>
<description >
2019-06-21 23:04:47 +00:00
Converts from a type to another in the best way possible. The [code]type[/code] parameter uses the enum [code]TYPE_*[/code] in [@GlobalScope].
2017-09-12 20:42:36 +00:00
[codeblock]
a = Vector2(1, 0)
2019-06-21 23:04:47 +00:00
# Prints 1
2017-09-12 20:42:36 +00:00
print(a.length())
a = convert(a, TYPE_STRING)
2019-06-21 23:04:47 +00:00
# Prints 6 as "(1, 0)" is 6 characters
2017-09-12 20:42:36 +00:00
print(a.length())
[/codeblock]
</description>
</method>
<method name= "cos" >
<return type= "float" >
</return>
<argument index= "0" name= "s" type= "float" >
</argument>
<description >
2017-09-17 22:36:34 +00:00
Returns the cosine of angle [code]s[/code] in radians.
2017-09-12 20:42:36 +00:00
[codeblock]
2019-06-21 23:04:47 +00:00
# Prints 1 then -1
2018-12-14 08:37:19 +00:00
print(cos(PI * 2))
2017-09-12 20:42:36 +00:00
print(cos(PI))
[/codeblock]
</description>
</method>
<method name= "cosh" >
<return type= "float" >
</return>
<argument index= "0" name= "s" type= "float" >
</argument>
<description >
2017-09-17 22:36:34 +00:00
Returns the hyperbolic cosine of [code]s[/code] in radians.
2017-09-12 20:42:36 +00:00
[codeblock]
2019-06-21 23:04:47 +00:00
# Prints 1.543081
2017-09-12 20:42:36 +00:00
print(cosh(1))
[/codeblock]
</description>
</method>
<method name= "db2linear" >
<return type= "float" >
</return>
<argument index= "0" name= "db" type= "float" >
</argument>
<description >
2017-09-17 22:36:34 +00:00
Converts from decibels to linear energy (audio).
2017-09-12 20:42:36 +00:00
</description>
</method>
<method name= "decimals" >
2019-05-15 10:51:58 +00:00
<return type= "int" >
2017-09-12 20:42:36 +00:00
</return>
<argument index= "0" name= "step" type= "float" >
</argument>
<description >
2019-06-21 23:04:47 +00:00
Deprecated alias for [method step_decimals].
2017-09-12 20:42:36 +00:00
</description>
</method>
<method name= "dectime" >
<return type= "float" >
</return>
<argument index= "0" name= "value" type= "float" >
</argument>
<argument index= "1" name= "amount" type= "float" >
</argument>
<argument index= "2" name= "step" type= "float" >
</argument>
<description >
2017-09-17 22:36:34 +00:00
Returns the result of [code]value[/code] decreased by [code]step[/code] * [code]amount[/code].
2017-09-12 20:42:36 +00:00
[codeblock]
# a = 59
a = dectime(60, 10, 0.1))
[/codeblock]
</description>
</method>
<method name= "deg2rad" >
<return type= "float" >
</return>
<argument index= "0" name= "deg" type= "float" >
</argument>
<description >
Returns degrees converted to radians.
[codeblock]
# r is 3.141593
r = deg2rad(180)
[/codeblock]
</description>
</method>
<method name= "dict2inst" >
<return type= "Object" >
</return>
<argument index= "0" name= "dict" type= "Dictionary" >
</argument>
<description >
2017-09-17 22:36:34 +00:00
Converts a previously converted instance to a dictionary, back into an instance. Useful for deserializing.
2017-09-12 20:42:36 +00:00
</description>
</method>
<method name= "ease" >
<return type= "float" >
</return>
<argument index= "0" name= "s" type= "float" >
</argument>
<argument index= "1" name= "curve" type= "float" >
</argument>
<description >
Easing function, based on exponent. 0 is constant, 1 is linear, 0 to 1 is ease-in, 1+ is ease out. Negative values are in-out/out in.
</description>
</method>
<method name= "exp" >
<return type= "float" >
</return>
<argument index= "0" name= "s" type= "float" >
</argument>
<description >
2018-04-15 16:40:31 +00:00
The natural exponential function. It raises the mathematical constant [b]e[/b] to the power of [code]s[/code] and returns it.
[b]e[/b] has an approximate value of 2.71828.
2017-09-13 06:18:51 +00:00
[codeblock]
2019-06-21 23:04:47 +00:00
a = exp(2) # Approximately 7.39
2017-09-13 06:18:51 +00:00
[/codeblock]
2017-09-12 20:42:36 +00:00
</description>
</method>
<method name= "floor" >
<return type= "float" >
</return>
<argument index= "0" name= "s" type= "float" >
</argument>
<description >
2017-09-17 22:36:34 +00:00
Rounds [code]s[/code] to the closest smaller integer and returns it.
2017-09-13 06:18:51 +00:00
[codeblock]
# a is 2
a = floor(2.99)
# a is -3
a = floor(-2.99)
[/codeblock]
2017-09-12 20:42:36 +00:00
</description>
</method>
<method name= "fmod" >
<return type= "float" >
</return>
2018-10-27 20:12:27 +00:00
<argument index= "0" name= "a" type= "float" >
2017-09-12 20:42:36 +00:00
</argument>
2018-10-27 20:12:27 +00:00
<argument index= "1" name= "b" type= "float" >
2017-09-12 20:42:36 +00:00
</argument>
<description >
2018-10-27 20:12:27 +00:00
Returns the floating-point remainder of [code]a/b[/code], keeping the sign of [code]a[/code].
2017-09-12 20:42:36 +00:00
[codeblock]
2019-06-21 23:04:47 +00:00
# Remainder is 1.5
2017-09-17 22:36:34 +00:00
var remainder = fmod(7, 5.5)
2017-09-12 20:42:36 +00:00
[/codeblock]
2018-10-27 20:12:27 +00:00
For the integer remainder operation, use the % operator.
2017-09-12 20:42:36 +00:00
</description>
</method>
<method name= "fposmod" >
<return type= "float" >
</return>
2018-10-27 20:12:27 +00:00
<argument index= "0" name= "a" type= "float" >
2017-09-12 20:42:36 +00:00
</argument>
2018-10-27 20:12:27 +00:00
<argument index= "1" name= "b" type= "float" >
</argument>
<description >
Returns the floating-point modulus of [code]a/b[/code] that wraps equally in positive and negative.
[codeblock]
var i = -6
while i < 5:
prints(i, fposmod(i, 3))
i += 1
[/codeblock]
Produces:
[codeblock]
-6 0
-5 1
-4 2
-3 0
-2 1
-1 2
0 0
1 1
2 2
3 0
4 1
[/codeblock]
</description>
</method>
<method name= "posmod" >
<return type= "int" >
</return>
<argument index= "0" name= "a" type= "int" >
</argument>
<argument index= "1" name= "b" type= "int" >
2017-09-12 20:42:36 +00:00
</argument>
<description >
2018-10-27 20:12:27 +00:00
Returns the integer modulus of [code]a/b[/code] that wraps equally in positive and negative.
2017-09-13 06:18:51 +00:00
[codeblock]
2018-10-27 20:12:27 +00:00
var i = -6
while i < 5:
prints(i, posmod(i, 3))
2017-09-13 06:18:51 +00:00
i += 1
[/codeblock]
Produces:
[codeblock]
2018-10-27 20:12:27 +00:00
-6 0
-5 1
-4 2
-3 0
-2 1
-1 2
0 0
1 1
2 2
3 0
4 1
2017-09-13 06:18:51 +00:00
[/codeblock]
2017-09-12 20:42:36 +00:00
</description>
</method>
<method name= "funcref" >
2018-07-26 09:56:21 +00:00
<return type= "FuncRef" >
2017-09-12 20:42:36 +00:00
</return>
<argument index= "0" name= "instance" type= "Object" >
</argument>
<argument index= "1" name= "funcname" type= "String" >
</argument>
<description >
2017-09-17 22:36:34 +00: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 06:18:51 +00:00
[codeblock]
func foo():
return("bar")
a = funcref(self, "foo")
2019-06-21 23:04:47 +00:00
print(a.call_func()) # Prints bar
2017-09-13 06:18:51 +00:00
[/codeblock]
2017-09-12 20:42:36 +00:00
</description>
</method>
2018-07-26 09:56:21 +00:00
<method name= "get_stack" >
2018-09-10 22:18:05 +00:00
<return type= "Array" >
2018-07-26 09:56:21 +00:00
</return>
<description >
2019-01-06 12:57:23 +00: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 09:56:21 +00:00
</description>
</method>
2017-09-12 20:42:36 +00:00
<method name= "hash" >
<return type= "int" >
</return>
<argument index= "0" name= "var" type= "Variant" >
</argument>
<description >
Returns the integer hash of the variable passed.
[codeblock]
2019-06-21 23:04:47 +00:00
print(hash("a")) # Prints 177670
2017-09-12 20:42:36 +00:00
[/codeblock]
</description>
</method>
<method name= "inst2dict" >
<return type= "Dictionary" >
</return>
<argument index= "0" name= "inst" type= "Object" >
</argument>
<description >
2017-09-17 22:36:34 +00:00
Returns the passed instance converted to a dictionary (useful for serializing).
2017-09-12 20:42:36 +00: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" >
<return type= "Object" >
</return>
<argument index= "0" name= "instance_id" type= "int" >
</argument>
<description >
2017-09-17 22:36:34 +00:00
Returns the Object that corresponds to [code]instance_id[/code]. All Objects have a unique instance ID.
2017-09-12 20:42:36 +00:00
[codeblock]
var foo = "bar"
func _ready():
var id = get_instance_id()
var inst = instance_from_id(id)
2019-06-21 23:04:47 +00:00
print(inst.foo) # Prints bar
2017-09-12 20:42:36 +00:00
[/codeblock]
</description>
</method>
<method name= "inverse_lerp" >
<return type= "float" >
</return>
<argument index= "0" name= "from" type= "float" >
</argument>
<argument index= "1" name= "to" type= "float" >
</argument>
2018-01-17 09:43:23 +00:00
<argument index= "2" name= "weight" type= "float" >
2017-09-12 20:42:36 +00:00
</argument>
<description >
Returns a normalized value considering the given range.
[codeblock]
2019-06-21 23:04:47 +00:00
inverse_lerp(3, 5, 4) # Returns 0.5
2017-09-12 20:42:36 +00:00
[/codeblock]
</description>
</method>
2018-07-31 23:34:20 +00:00
<method name= "is_equal_approx" >
<return type= "bool" >
</return>
<argument index= "0" name= "a" type= "float" >
</argument>
<argument index= "1" name= "b" type= "float" >
</argument>
<description >
Returns True/False whether [code]a[/code] and [code]b[/code] are approximately equal to each other.
</description>
</method>
2017-09-12 20:42:36 +00:00
<method name= "is_inf" >
<return type= "bool" >
</return>
<argument index= "0" name= "s" type= "float" >
</argument>
<description >
2019-01-06 12:57:23 +00:00
Returns whether [code]s[/code] is an infinity value (either positive infinity or negative infinity).
2017-09-12 20:42:36 +00:00
</description>
</method>
2018-05-12 07:38:00 +00:00
<method name= "is_instance_valid" >
<return type= "bool" >
</return>
<argument index= "0" name= "instance" type= "Object" >
</argument>
<description >
2019-01-06 12:57:23 +00:00
Returns whether [code]instance[/code] is a valid object (e.g. has not been deleted from memory).
2018-05-12 07:38:00 +00:00
</description>
</method>
2017-09-12 20:42:36 +00:00
<method name= "is_nan" >
<return type= "bool" >
</return>
<argument index= "0" name= "s" type= "float" >
</argument>
<description >
2019-01-06 12:57:23 +00:00
Returns whether [code]s[/code] is a NaN (Not-A-Number) value.
2017-09-12 20:42:36 +00:00
</description>
</method>
2018-07-31 23:34:20 +00:00
<method name= "is_zero_approx" >
<return type= "bool" >
</return>
<argument index= "0" name= "s" type= "float" >
</argument>
<description >
Returns True/False whether [code]s[/code] is zero or almost zero.
</description>
</method>
2017-09-12 20:42:36 +00:00
<method name= "len" >
<return type= "int" >
</return>
<argument index= "0" name= "var" type= "Variant" >
</argument>
<description >
2018-07-28 20:44:58 +00: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 20:42:36 +00:00
[codeblock]
a = [1, 2, 3, 4]
2019-06-21 23:04:47 +00:00
len(a) # Returns 4
2017-09-12 20:42:36 +00:00
[/codeblock]
</description>
</method>
<method name= "lerp" >
2019-01-18 09:46:52 +00:00
<return type= "Variant" >
2017-09-12 20:42:36 +00:00
</return>
2018-05-12 07:38:00 +00:00
<argument index= "0" name= "from" type= "Variant" >
2017-09-12 20:42:36 +00:00
</argument>
2018-05-12 07:38:00 +00:00
<argument index= "1" name= "to" type= "Variant" >
2017-09-12 20:42:36 +00:00
</argument>
<argument index= "2" name= "weight" type= "float" >
</argument>
<description >
2017-09-17 22:36:34 +00:00
Linearly interpolates between two values by a normalized value.
2019-01-18 09:46:52 +00: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 06:18:51 +00:00
[codeblock]
2019-06-21 23:04:47 +00: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 06:18:51 +00:00
[/codeblock]
2017-09-12 20:42:36 +00:00
</description>
</method>
2019-07-14 04:30:45 +00:00
<method name= "lerp_angle" >
<return type= "float" >
</return>
<argument index= "0" name= "from" type= "float" >
</argument>
<argument index= "1" name= "to" type= "float" >
</argument>
<argument index= "2" name= "weight" type= "float" >
</argument>
<description >
Linearly interpolates between two angles (in radians) by a normalized value.
Similar to [method lerp] but interpolate correctly when the angles wrap around [constant @GDScript.TAU].
[codeblock]
extends Sprite
var elapsed = 0.0
func _process(delta):
var min_angle = deg2rad(0.0)
var max_angle = deg2rad(90.0)
rotation = lerp_angle(min_angle, max_angle, elapsed)
elapsed += delta
[/codeblock]
</description>
</method>
2017-09-12 20:42:36 +00:00
<method name= "linear2db" >
<return type= "float" >
</return>
<argument index= "0" name= "nrg" type= "float" >
</argument>
<description >
2017-09-17 22:36:34 +00:00
Converts from linear energy to decibels (audio).
2017-09-12 20:42:36 +00:00
</description>
</method>
<method name= "load" >
2018-07-26 09:56:21 +00:00
<return type= "Resource" >
2017-09-12 20:42:36 +00:00
</return>
<argument index= "0" name= "path" type= "String" >
</argument>
<description >
2018-07-28 20:44:58 +00:00
Loads a resource from the filesystem located at [code]path[/code].
2019-06-21 23:04:47 +00:00
[b]Note:[/b] Resource paths can be obtained by right-clicking on a resource in the FileSystem dock and choosing [b]Copy Path[/b].
2017-09-12 20:42:36 +00:00
[codeblock]
2019-06-21 23:04:47 +00:00
# Load a scene called main located in the root of the project directory
2017-09-12 20:42:36 +00:00
var main = load("res://main.tscn")
[/codeblock]
</description>
</method>
<method name= "log" >
<return type= "float" >
</return>
<argument index= "0" name= "s" type= "float" >
</argument>
<description >
2018-07-28 20:44:58 +00:00
Natural logarithm. The amount of time needed to reach a certain level of continuous growth.
2019-06-21 23:04:47 +00: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 20:42:36 +00:00
[codeblock]
2019-06-21 23:04:47 +00:00
log(10) # Returns 2.302585
2017-09-12 20:42:36 +00:00
[/codeblock]
</description>
</method>
<method name= "max" >
<return type= "float" >
</return>
<argument index= "0" name= "a" type= "float" >
</argument>
<argument index= "1" name= "b" type= "float" >
</argument>
<description >
Returns the maximum of two values.
[codeblock]
2019-06-21 23:04:47 +00:00
max(1, 2) # Returns 2
max(-3.99, -4) # Returns -3.99
2017-09-12 20:42:36 +00:00
[/codeblock]
</description>
</method>
<method name= "min" >
<return type= "float" >
</return>
<argument index= "0" name= "a" type= "float" >
</argument>
<argument index= "1" name= "b" type= "float" >
</argument>
<description >
Returns the minimum of two values.
[codeblock]
2019-06-21 23:04:47 +00:00
min(1, 2) # Returns 1
min(-3.99, -4) # Returns -4
2017-09-12 20:42:36 +00:00
[/codeblock]
</description>
</method>
2019-04-07 21:40:56 +00:00
<method name= "move_toward" >
<return type= "float" >
</return>
<argument index= "0" name= "from" type= "float" >
</argument>
<argument index= "1" name= "to" type= "float" >
</argument>
<argument index= "2" name= "delta" type= "float" >
</argument>
<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]
2019-06-21 23:04:47 +00:00
move_toward(10, 5, 4) # Returns 6
2019-04-07 21:40:56 +00:00
[/codeblock]
</description>
</method>
2017-09-12 20:42:36 +00:00
<method name= "nearest_po2" >
<return type= "int" >
</return>
2018-01-16 16:31:10 +00:00
<argument index= "0" name= "value" type= "int" >
2017-09-12 20:42:36 +00:00
</argument>
<description >
2018-01-17 10:28:59 +00:00
Returns the nearest larger power of 2 for integer [code]value[/code].
2017-09-12 20:42:36 +00:00
[codeblock]
2019-06-21 23:04:47 +00:00
nearest_po2(3) # Returns 4
nearest_po2(4) # Returns 4
nearest_po2(5) # Returns 8
2017-09-12 20:42:36 +00:00
[/codeblock]
</description>
</method>
<method name= "parse_json" >
<return type= "Variant" >
</return>
<argument index= "0" name= "json" type= "String" >
</argument>
<description >
Parse JSON text to a Variant (use [method typeof] to check if it is what you expect).
2017-09-17 22:36:34 +00:00
Be aware that the JSON specification does not define integer or float types, but only a number type. Therefore, parsing a JSON text will convert all numerical values to [float] types.
2018-02-02 04:32:12 +00:00
Note that 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 20:42:36 +00:00
[codeblock]
p = parse_json('["a", "b", "c"]')
if typeof(p) == TYPE_ARRAY:
2019-06-21 23:04:47 +00:00
print(p[0]) # Prints a
2017-09-12 20:42:36 +00:00
else:
print("unexpected results")
[/codeblock]
</description>
</method>
2017-10-12 23:15:45 +00:00
<method name= "polar2cartesian" >
<return type= "Vector2" >
</return>
<argument index= "0" name= "r" type= "float" >
</argument>
<argument index= "1" name= "th" type= "float" >
</argument>
<description >
2019-06-21 23:04:47 +00: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-12 23:15:45 +00:00
</description>
</method>
2017-09-12 20:42:36 +00:00
<method name= "pow" >
<return type= "float" >
</return>
<argument index= "0" name= "x" type= "float" >
</argument>
<argument index= "1" name= "y" type= "float" >
</argument>
<description >
2017-09-17 22:36:34 +00:00
Returns the result of [code]x[/code] raised to the power of [code]y[/code].
2017-09-12 20:42:36 +00:00
[codeblock]
2019-06-21 23:04:47 +00:00
pow(2, 5) # Returns 32
2017-09-12 20:42:36 +00:00
[/codeblock]
</description>
</method>
<method name= "preload" >
<return type= "Resource" >
</return>
<argument index= "0" name= "path" type= "String" >
</argument>
<description >
2018-07-28 20:44:58 +00:00
Returns a resource from the filesystem that is loaded during script parsing.
[b]Note:[/b] Resource paths can be obtained by right clicking on a resource in the Assets Panel and choosing "Copy Path".
2017-09-12 20:42:36 +00:00
[codeblock]
2019-06-21 23:04:47 +00:00
# Load a scene called main located in the root of the project directory
2017-09-12 20:42:36 +00:00
var main = preload("res://main.tscn")
2017-09-13 06:18:51 +00:00
[/codeblock]
2017-09-12 20:42:36 +00:00
</description>
</method>
<method name= "print" qualifiers= "vararg" >
<return type= "void" >
</return>
<description >
Converts one or more arguments to strings in the best way possible and prints them to the console.
[codeblock]
2018-12-14 08:37:19 +00:00
a = [1, 2, 3]
2019-06-21 23:04:47 +00:00
print("a", "b", a) # Prints ab[1, 2, 3]
2017-09-12 20:42:36 +00:00
[/codeblock]
</description>
</method>
2018-07-26 09:56:21 +00:00
<method name= "print_debug" qualifiers= "vararg" >
<return type= "void" >
</return>
<description >
2019-01-06 12:57:23 +00:00
Like [method print], but prints only when used in debug mode.
2018-07-26 09:56:21 +00:00
</description>
</method>
2017-09-12 20:42:36 +00:00
<method name= "print_stack" >
<return type= "void" >
</return>
<description >
2017-09-17 22:36:34 +00:00
Prints a stack track at code location, only works when running with debugger turned on.
2017-09-13 06:18:51 +00:00
Output in the console would look something like this:
[codeblock]
Frame 0 - res://test.gd:16 in function '_process'
[/codeblock]
2017-09-12 20:42:36 +00:00
</description>
</method>
<method name= "printerr" qualifiers= "vararg" >
<return type= "void" >
</return>
<description >
2017-09-17 22:36:34 +00:00
Prints one or more arguments to strings in the best way possible to standard error line.
2017-09-13 06:18:51 +00:00
[codeblock]
printerr("prints to stderr")
[/codeblock]
2017-09-12 20:42:36 +00:00
</description>
</method>
<method name= "printraw" qualifiers= "vararg" >
<return type= "void" >
</return>
<description >
2017-09-17 22:36:34 +00: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 06:18:51 +00:00
[codeblock]
printraw("A")
printraw("B")
2019-06-21 23:04:47 +00:00
# Prints AB
2017-09-13 06:18:51 +00:00
[/codeblock]
2017-09-12 20:42:36 +00:00
</description>
</method>
<method name= "prints" qualifiers= "vararg" >
<return type= "void" >
</return>
<description >
2017-09-17 22:36:34 +00:00
Prints one or more arguments to the console with a space between each argument.
2017-09-13 06:18:51 +00:00
[codeblock]
2019-06-21 23:04:47 +00:00
prints("A", "B", "C") # Prints A B C
2017-09-13 06:18:51 +00:00
[/codeblock]
2017-09-12 20:42:36 +00:00
</description>
</method>
<method name= "printt" qualifiers= "vararg" >
<return type= "void" >
</return>
<description >
2017-09-17 22:36:34 +00:00
Prints one or more arguments to the console with a tab between each argument.
2017-09-13 06:18:51 +00:00
[codeblock]
2019-06-21 23:04:47 +00:00
printt("A", "B", "C") # Prints A B C
2017-09-13 06:18:51 +00:00
[/codeblock]
2017-09-12 20:42:36 +00:00
</description>
</method>
2018-11-10 13:21:34 +00:00
<method name= "push_error" >
<return type= "void" >
</return>
<argument index= "0" name= "message" type= "String" >
</argument>
<description >
2018-12-07 03:11:07 +00:00
Pushes an error message to Godot's built-in debugger and to the OS terminal.
[codeblock]
2019-06-21 23:04:47 +00:00
push_error("test error") # Prints "test error" to debugger and terminal as error call
2018-12-07 03:11:07 +00:00
[/codeblock]
2018-11-10 13:21:34 +00:00
</description>
</method>
<method name= "push_warning" >
<return type= "void" >
</return>
<argument index= "0" name= "message" type= "String" >
</argument>
<description >
2018-12-07 03:11:07 +00:00
Pushes a warning message to Godot's built-in debugger and to the OS terminal.
[codeblock]
2019-06-21 23:04:47 +00:00
push_warning("test warning") # Prints "test warning" to debugger and terminal as warning call
2018-12-07 03:11:07 +00:00
[/codeblock]
2018-11-10 13:21:34 +00:00
</description>
</method>
2017-09-12 20:42:36 +00:00
<method name= "rad2deg" >
<return type= "float" >
</return>
<argument index= "0" name= "rad" type= "float" >
</argument>
<description >
2017-09-17 22:36:34 +00:00
Converts from radians to degrees.
2017-09-13 06:18:51 +00:00
[codeblock]
2019-06-21 23:04:47 +00:00
rad2deg(0.523599) # Returns 30
2017-09-13 06:18:51 +00:00
[/codeblock]
2017-09-12 20:42:36 +00:00
</description>
</method>
<method name= "rand_range" >
<return type= "float" >
</return>
<argument index= "0" name= "from" type= "float" >
</argument>
<argument index= "1" name= "to" type= "float" >
</argument>
<description >
2019-02-18 08:45:10 +00:00
Random range, any floating point value between [code]from[/code] and [code]to[/code].
2017-09-13 06:18:51 +00:00
[codeblock]
2019-06-21 23:04:47 +00:00
prints(rand_range(0, 1), rand_range(0, 1)) # Prints e.g. 0.135591 0.405263
2017-09-13 06:18:51 +00:00
[/codeblock]
2017-09-12 20:42:36 +00:00
</description>
</method>
<method name= "rand_seed" >
<return type= "Array" >
</return>
<argument index= "0" name= "seed" type= "int" >
</argument>
<description >
2017-09-17 22:36:34 +00: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 20:42:36 +00:00
</description>
</method>
<method name= "randf" >
<return type= "float" >
</return>
<description >
2019-02-18 08:45:10 +00:00
Returns a random floating point value on the interval [code][0, 1][/code].
2017-09-13 06:18:51 +00:00
[codeblock]
2019-06-21 23:04:47 +00:00
randf() # Returns e.g. 0.375671
2017-09-13 06:18:51 +00:00
[/codeblock]
2017-09-12 20:42:36 +00:00
</description>
</method>
<method name= "randi" >
<return type= "int" >
</return>
<description >
2019-02-21 10:21:41 +00:00
Returns a random unsigned 32 bit integer. Use remainder to obtain a random value in the interval [code][0, N][/code] (where N is smaller than 2^32 -1).
2017-09-13 06:18:51 +00:00
[codeblock]
2019-06-21 23:04:47 +00: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 06:18:51 +00:00
[/codeblock]
2017-09-12 20:42:36 +00:00
</description>
</method>
<method name= "randomize" >
<return type= "void" >
</return>
<description >
2017-09-17 22:36:34 +00: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 06:18:51 +00:00
[codeblock]
func _ready():
randomize()
[/codeblock]
2017-09-12 20:42:36 +00:00
</description>
</method>
<method name= "range" qualifiers= "vararg" >
<return type= "Array" >
</return>
<description >
2017-09-17 22:36:34 +00: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 06:18:51 +00:00
[codeblock]
for i in range(4):
print(i)
for i in range(2, 5):
print(i)
for i in range(0, 6, 2):
print(i)
[/codeblock]
Output:
[codeblock]
0
1
2
3
2
3
4
0
2
4
[/codeblock]
2017-09-12 20:42:36 +00:00
</description>
</method>
<method name= "range_lerp" >
<return type= "float" >
</return>
<argument index= "0" name= "value" type= "float" >
</argument>
<argument index= "1" name= "istart" type= "float" >
</argument>
<argument index= "2" name= "istop" type= "float" >
</argument>
<argument index= "3" name= "ostart" type= "float" >
</argument>
<argument index= "4" name= "ostop" type= "float" >
</argument>
<description >
2017-09-17 22:36:34 +00:00
Maps a [code]value[/code] from range [code][istart, istop][/code] to [code][ostart, ostop][/code].
2017-09-12 20:42:36 +00:00
[codeblock]
2019-06-21 23:04:47 +00:00
range_lerp(75, 0, 100, -1, 1) # Returns 0.5
2017-09-12 20:42:36 +00:00
[/codeblock]
</description>
</method>
<method name= "round" >
<return type= "float" >
</return>
<argument index= "0" name= "s" type= "float" >
</argument>
<description >
2017-09-17 22:36:34 +00:00
Returns the integral value that is nearest to [code]s[/code], with halfway cases rounded away from zero.
2017-09-13 06:18:51 +00:00
[codeblock]
2019-06-21 23:04:47 +00:00
round(2.6) # Returns 3
2017-09-13 06:18:51 +00:00
[/codeblock]
2017-09-12 20:42:36 +00:00
</description>
</method>
<method name= "seed" >
<return type= "void" >
</return>
<argument index= "0" name= "seed" type= "int" >
</argument>
<description >
2017-09-17 22:36:34 +00:00
Sets seed for the random number generator.
2017-09-13 06:18:51 +00:00
[codeblock]
my_seed = "Godot Rocks"
seed(my_seed.hash())
[/codeblock]
2017-09-12 20:42:36 +00:00
</description>
</method>
<method name= "sign" >
<return type= "float" >
</return>
<argument index= "0" name= "s" type= "float" >
</argument>
<description >
2017-12-29 12:11:27 +00:00
Returns the sign of [code]s[/code]: -1 or 1. Returns 0 if [code]s[/code] is 0.
2017-09-13 06:18:51 +00:00
[codeblock]
2019-06-21 23:04:47 +00:00
sign(-6) # Returns -1
sign(0) # Returns 0
sign(6) # Returns 1
2017-09-13 06:18:51 +00:00
[/codeblock]
2017-09-12 20:42:36 +00:00
</description>
</method>
<method name= "sin" >
<return type= "float" >
</return>
<argument index= "0" name= "s" type= "float" >
</argument>
<description >
2017-09-17 22:36:34 +00:00
Returns the sine of angle [code]s[/code] in radians.
2017-09-13 06:18:51 +00:00
[codeblock]
2019-06-21 23:04:47 +00:00
sin(0.523599) # Returns 0.5
2017-09-13 06:18:51 +00:00
[/codeblock]
2017-09-12 20:42:36 +00:00
</description>
</method>
<method name= "sinh" >
<return type= "float" >
</return>
<argument index= "0" name= "s" type= "float" >
</argument>
<description >
2017-09-17 22:36:34 +00:00
Returns the hyperbolic sine of [code]s[/code].
2017-09-13 06:18:51 +00:00
[codeblock]
2019-06-21 23:04:47 +00:00
a = log(2.0) # Returns 0.693147
sinh(a) # Returns 0.75
2017-09-13 06:18:51 +00:00
[/codeblock]
2017-09-12 20:42:36 +00:00
</description>
</method>
2019-03-19 11:39:43 +00:00
<method name= "smoothstep" >
<return type= "float" >
</return>
<argument index= "0" name= "from" type= "float" >
</argument>
<argument index= "1" name= "to" type= "float" >
</argument>
<argument index= "2" name= "weight" type= "float" >
</argument>
<description >
Returns a number smoothly interpolated between the [code]from[/code] and [code]to[/code], based on the [code]weight[/code]. Similar to [method lerp], but interpolates faster at the beginning and slower at the end.
[codeblock]
2019-06-21 23:04:47 +00:00
smoothstep(0, 2, 0.5) # Returns 0.15
smoothstep(0, 2, 1.0) # Returns 0.5
smoothstep(0, 2, 2.0) # Returns 1.0
2019-03-19 11:39:43 +00:00
[/codeblock]
</description>
</method>
2017-09-12 20:42:36 +00:00
<method name= "sqrt" >
<return type= "float" >
</return>
<argument index= "0" name= "s" type= "float" >
</argument>
<description >
2017-09-17 22:36:34 +00:00
Returns the square root of [code]s[/code].
2017-09-13 06:18:51 +00:00
[codeblock]
2019-06-21 23:04:47 +00:00
sqrt(9) # Returns 3
2017-09-13 06:18:51 +00:00
[/codeblock]
2017-09-12 20:42:36 +00:00
</description>
</method>
2018-10-26 00:20:20 +00:00
<method name= "step_decimals" >
2019-05-15 10:51:58 +00:00
<return type= "int" >
2018-10-26 00:20:20 +00:00
</return>
<argument index= "0" name= "step" type= "float" >
</argument>
<description >
Returns the position of the first non-zero digit, after the decimal point.
[codeblock]
# n is 0
n = step_decimals(5)
# n is 4
n = step_decimals(1.0005)
# n is 9
n = step_decimals(0.000000005)
[/codeblock]
</description>
</method>
2017-09-12 20:42:36 +00:00
<method name= "stepify" >
<return type= "float" >
</return>
<argument index= "0" name= "s" type= "float" >
</argument>
<argument index= "1" name= "step" type= "float" >
</argument>
<description >
2017-09-17 22:36:34 +00:00
Snaps float value [code]s[/code] to a given [code]step[/code].
2017-09-12 20:42:36 +00:00
</description>
</method>
<method name= "str" qualifiers= "vararg" >
<return type= "String" >
</return>
<description >
2017-09-17 22:36:34 +00:00
Converts one or more arguments to string in the best way possible.
2017-09-13 06:18:51 +00:00
[codeblock]
var a = [10, 20, 30]
var b = str(a);
2019-06-21 23:04:47 +00:00
len(a) # Returns 3
len(b) # Returns 12
2017-09-13 06:18:51 +00:00
[/codeblock]
2017-09-12 20:42:36 +00:00
</description>
</method>
<method name= "str2var" >
<return type= "Variant" >
</return>
<argument index= "0" name= "string" type= "String" >
</argument>
<description >
2017-09-17 22:36:34 +00:00
Converts a formatted string that was returned by [method var2str] to the original value.
2017-09-13 06:18:51 +00:00
[codeblock]
a = '{ "a": 1, "b": 2 }'
b = str2var(a)
2019-06-21 23:04:47 +00:00
print(b["a"]) # Prints 1
2017-09-13 06:18:51 +00:00
[/codeblock]
2017-09-12 20:42:36 +00:00
</description>
</method>
<method name= "tan" >
<return type= "float" >
</return>
<argument index= "0" name= "s" type= "float" >
</argument>
<description >
2017-09-17 22:36:34 +00:00
Returns the tangent of angle [code]s[/code] in radians.
2017-09-13 06:18:51 +00:00
[codeblock]
2019-06-21 23:04:47 +00:00
tan(deg2rad(45)) # Returns 1
2017-09-13 06:18:51 +00:00
[/codeblock]
2017-09-12 20:42:36 +00:00
</description>
</method>
<method name= "tanh" >
<return type= "float" >
</return>
<argument index= "0" name= "s" type= "float" >
</argument>
<description >
2017-09-17 22:36:34 +00:00
Returns the hyperbolic tangent of [code]s[/code].
2017-09-13 06:18:51 +00:00
[codeblock]
2019-06-21 23:04:47 +00:00
a = log(2.0) # Returns 0.693147
tanh(a) # Returns 0.6
2017-09-13 06:18:51 +00:00
[/codeblock]
2017-09-12 20:42:36 +00:00
</description>
</method>
<method name= "to_json" >
<return type= "String" >
</return>
<argument index= "0" name= "var" type= "Variant" >
</argument>
<description >
2017-09-17 22:36:34 +00: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 06:18:51 +00:00
[codeblock]
2019-06-21 23:04:47 +00:00
a = { "a": 1, "b": 2 }
2017-09-13 06:18:51 +00:00
b = to_json(a)
print(b) # {"a":1, "b":2}
[/codeblock]
2017-09-12 20:42:36 +00:00
</description>
</method>
<method name= "type_exists" >
<return type= "bool" >
</return>
<argument index= "0" name= "type" type= "String" >
</argument>
<description >
2017-09-17 22:36:34 +00:00
Returns whether the given class exists in [ClassDB].
2017-09-12 20:42:36 +00:00
[codeblock]
2019-06-21 23:04:47 +00:00
type_exists("Sprite") # Returns true
type_exists("Variant") # Returns false
2017-09-12 20:42:36 +00:00
[/codeblock]
</description>
</method>
<method name= "typeof" >
<return type= "int" >
</return>
<argument index= "0" name= "what" type= "Variant" >
</argument>
<description >
2019-06-21 23:04:47 +00:00
Returns the internal type of the given Variant object, using the [code]TYPE_*[/code] enum in [@GlobalScope].
2017-09-13 06:18:51 +00:00
[codeblock]
p = parse_json('["a", "b", "c"]')
if typeof(p) == TYPE_ARRAY:
2019-06-21 23:04:47 +00:00
print(p[0]) # Prints a
2017-09-13 06:18:51 +00:00
else:
print("unexpected results")
[/codeblock]
2017-09-12 20:42:36 +00:00
</description>
</method>
<method name= "validate_json" >
<return type= "String" >
</return>
<argument index= "0" name= "json" type= "String" >
</argument>
<description >
2017-09-17 22:36:34 +00:00
Checks that [code]json[/code] is valid JSON data. Returns empty string if valid. Returns error message if not valid.
2017-09-13 06:18:51 +00:00
[codeblock]
j = to_json([1, 2, 3])
v = validate_json(j)
if not v:
print("valid")
else:
prints("invalid", v)
[/codeblock]
2017-09-12 20:42:36 +00:00
</description>
</method>
<method name= "var2bytes" >
<return type= "PoolByteArray" >
</return>
<argument index= "0" name= "var" type= "Variant" >
</argument>
2019-03-26 15:52:42 +00:00
<argument index= "1" name= "full_objects" type= "bool" default= "false" >
</argument>
2017-09-12 20:42:36 +00:00
<description >
2019-03-26 15:52:42 +00: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 20:42:36 +00:00
</description>
</method>
<method name= "var2str" >
<return type= "String" >
</return>
<argument index= "0" name= "var" type= "Variant" >
</argument>
<description >
2017-09-17 22:36:34 +00:00
Converts a Variant [code]var[/code] to a formatted string that can later be parsed using [method str2var].
2017-09-13 06:18:51 +00:00
[codeblock]
2019-06-21 23:04:47 +00:00
a = { "a": 1, "b": 2 }
2017-09-13 06:18:51 +00:00
print(var2str(a))
[/codeblock]
prints
[codeblock]
{
"a": 1,
"b": 2
}
[/codeblock]
2017-09-12 20:42:36 +00:00
</description>
</method>
<method name= "weakref" >
2018-07-26 09:56:21 +00:00
<return type= "WeakRef" >
2017-09-12 20:42:36 +00:00
</return>
<argument index= "0" name= "obj" type= "Object" >
</argument>
<description >
2017-09-17 22:36:34 +00:00
Returns a weak reference to an object.
2017-09-12 20:42:36 +00: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 16:09:37 +00:00
<method name= "wrapf" >
<return type= "float" >
</return>
<argument index= "0" name= "value" type= "float" >
</argument>
<argument index= "1" name= "min" type= "float" >
</argument>
<argument index= "2" name= "max" type= "float" >
</argument>
<description >
Wraps float [code]value[/code] between [code]min[/code] and [code]max[/code].
Usable for creating loop-alike behavior or infinite surfaces.
[codeblock]
# a is 0.5
a = wrapf(10.5, 0.0, 10.0)
[/codeblock]
[codeblock]
# a is 9.5
a = wrapf(-0.5, 0.0, 10.0)
[/codeblock]
[codeblock]
2019-06-21 23:04:47 +00:00
# Infinite loop between 0.0 and 0.99
2017-11-04 16:09:37 +00:00
f = wrapf(f + 0.1, 0.0, 1.0)
[/codeblock]
2019-06-25 06:36:10 +00:00
[codeblock]
2019-06-21 23:04:47 +00:00
# Infinite rotation (in radians)
2019-06-25 06:36:10 +00:00
angle = wrapf(angle + 0.1, 0.0, TAU)
[/codeblock]
2019-06-21 23:04:47 +00:00
[b]Note:[/b] If you just want to wrap between 0.0 and [code]n[/code] (where [code]n[/code] is a positive floating-point value), it is better for performance to use the [method fmod] method like [code]fmod(number, n)[/code].
[code]wrapf[/code] is more flexible than using the [method fmod] approach by giving the user a simple control over the minimum value. It also fully supports negative numbers, e.g.
2019-06-25 06:36:10 +00:00
[codeblock]
2019-06-21 23:04:47 +00:00
# Infinite rotation (in radians)
2019-06-25 06:36:10 +00:00
angle = wrapf(angle + 0.1, -PI, PI)
[/codeblock]
2017-11-04 16:09:37 +00:00
</description>
</method>
<method name= "wrapi" >
<return type= "int" >
</return>
<argument index= "0" name= "value" type= "int" >
</argument>
<argument index= "1" name= "min" type= "int" >
</argument>
<argument index= "2" name= "max" type= "int" >
</argument>
<description >
Wraps integer [code]value[/code] between [code]min[/code] and [code]max[/code].
Usable for creating loop-alike behavior or infinite surfaces.
[codeblock]
# a is 0
a = wrapi(10, 0, 10)
[/codeblock]
[codeblock]
# a is 9
a = wrapi(-1, 0, 10)
[/codeblock]
[codeblock]
2019-06-21 23:04:47 +00:00
# Infinite loop between 0 and 9
2017-11-04 16:09:37 +00:00
frame = wrapi(frame + 1, 0, 10)
[/codeblock]
2019-06-21 23:04:47 +00:00
[b]Note:[/b] If you just want to wrap between 0 and [code]n[/code] (where [code]n[/code] is a positive integer value), it is better for performance to use the modulo operator like [code]number % n[/code].
[code]wrapi[/code] is more flexible than using the modulo approach by giving the user a simple control over the minimum value. It also fully supports negative numbers, e.g.
2019-06-25 06:36:10 +00:00
[codeblock]
# result is -2
var result = wrapi(-6, -5, -1)
[/codeblock]
2017-11-04 16:09:37 +00:00
</description>
</method>
2017-09-12 20:42:36 +00:00
<method name= "yield" >
2017-11-16 17:38:18 +00:00
<return type= "GDScriptFunctionState" >
2017-09-12 20:42:36 +00:00
</return>
2018-02-19 09:47:16 +00:00
<argument index= "0" name= "object" type= "Object" default= "null" >
2017-09-12 20:42:36 +00:00
</argument>
2018-02-19 09:47:16 +00:00
<argument index= "1" name= "signal" type= "String" default= """" >
2017-09-12 20:42:36 +00:00
</argument>
<description >
2018-07-02 19:25:51 +00: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.
2017-09-12 20:42:36 +00:00
</description>
</method>
</methods>
<constants >
2017-11-24 22:16:30 +00:00
<constant name= "PI" value= "3.141593" >
2017-11-04 09:34:27 +00:00
Constant that represents how many times the diameter of a circle fits around its perimeter.
</constant>
2017-11-24 22:16:30 +00:00
<constant name= "TAU" value= "6.283185" >
2017-11-04 09:34:27 +00:00
The circle constant, the circumference of the unit circle.
2017-09-12 20:42:36 +00:00
</constant>
2017-11-24 22:16:30 +00:00
<constant name= "INF" value= "inf" >
2017-09-12 20:42:36 +00:00
A positive infinity. (For negative infinity, use -INF).
</constant>
2018-06-13 12:42:55 +00:00
<constant name= "NAN" value= "nan" >
2017-09-12 20:42:36 +00:00
Macro constant that expands to an expression of type float that represents a NaN.
The NaN values are used to identify undefined or non-representable values for floating-point elements, such as the square root of negative numbers or the result of 0/0.
</constant>
</constants>
</class>