Built-in GDScript functions. List of core built-in GDScript functions. Math functions and other utilities. Everything else is provided by objects. (Keywords: builtin, built in, global functions.) https://docs.godotengine.org/en/latest/tutorials/math/random_number_generation.html 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. [code]r8[/code] red channel [code]g8[/code] green channel [code]b8[/code] blue channel [code]a8[/code] alpha channel [codeblock] red = Color8(255, 0, 0) [/codeblock] 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 @GlobalScope.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. The optional [code]message[/code] argument, if given, is shown in addition to the generic "Assertion failed" message. You can use this to provide additional details about why the assertion failed. [codeblock] # Imagine we always want speed to be between 0 and 20. var speed = -10 assert(speed < 20) # True, the program will continue assert(speed >= 0) # False, the program will stop assert(speed >= 0 and speed < 20) # You can also combine the two conditional statements in one check assert(speed < 20, "speed = %f, but the speed limit is 20" % speed) # Show a message with clarifying details [/codeblock] Returns a character as a String of the given Unicode code point (which is compatible with ASCII code). [codeblock] a = char(65) # a is "A" a = char(65 + 32) # a is "a" a = char(8364) # a is "€" [/codeblock] Converts from a type to another in the best way possible. The [code]type[/code] parameter uses the [enum Variant.Type] values. [codeblock] a = Vector2(1, 0) # Prints 1 print(a.length()) a = convert(a, TYPE_STRING) # Prints 6 as "(1, 0)" is 6 characters print(a.length()) [/codeblock] Converts a dictionary (previously created with [method inst2dict]) back to an instance. Useful for deserializing. 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] Returns the passed instance converted to a dictionary (useful for serializing). [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] 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. [codeblock] a = [1, 2, 3, 4] len(a) # Returns 4 [/codeblock] 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. [codeblock] # 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. [/codeblock] [b]Important:[/b] The path must be absolute, a local path will just return [code]null[/code]. This method is a simplified version of [method ResourceLoader.load], which can be used for more advanced scenarios. 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. [codeblock] # Instance a scene. var diamond = preload("res://diamond.tscn").instantiate() [/codeblock] Like [method @GlobalScope.print], but prints only when used in debug mode. Prints a stack track at code location, only works when running with debugger turned on. Output in the console would look something like this: [codeblock] Frame 0 - res://test.gd:16 in function '_process' [/codeblock] 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). [codeblock] print(range(4)) print(range(2, 5)) print(range(0, 6, 2)) [/codeblock] Output: [codeblock] [0, 1, 2, 3] [2, 3, 4] [0, 2, 4] [/codeblock] Converts one or more arguments to string in the best way possible. [codeblock] var a = [10, 20, 30] var b = str(a); len(a) # Returns 3 len(b) # Returns 12 [/codeblock] Constant that represents how many times the diameter of a circle fits around its perimeter. This is equivalent to [code]TAU / 2[/code]. The circle constant, the circumference of the unit circle in radians. Positive infinity. For negative infinity, use -INF. "Not a Number", an invalid value. [code]NaN[/code] has special properties, including that it is not equal to itself. It is output by some invalid operations, such as dividing zero by zero.