class-description NEWS COMMUNITY STORE LABS SIGN UP LOGIN LOGOUT ROKOJORI NEWSLETTER SIGN UP LOGIN LOGOUT NEWS COMMUNITY STORE LABS TOGGLE FULLSCREEN VOLLBILD AN/AUS @GDScript
Built-in GDScript constants, functions, and annotations.

A list of GDScript-specific utility functions and annotations accessible from any script.

For the list of the global functions and constants see @GlobalScope.

Color Color8<>( int r8=, r8:int=, int g8=, g8:int=, int b8=, b8:int=, int a8=255, a8:int=255, ):Color

Returns a Color constructed from red (r8), green (g8), blue (b8), and optionally alpha (a8) integer channels, each divided by 255.0 for their final value. Using Color8 instead of the standard Color constructor is useful when you need to match exact color values in an Image.

var red = Color8(255, 0, 0) # Same as Color(1, 0, 0). var dark_blue = Color8(0, 0, 51) # Same as Color(0, 0, 0.2). var my_color = Color8(306, 255, 0, 102) # Same as Color(1.2, 1, 0, 0.4).

Note: Due to the lower precision of Color8 compared to the standard Color constructor, a color created with Color8 will generally not be equal to the same color created with the standard Color constructor. Use Color.is_equal_approx for comparisons to avoid issues with floating-point precision error.

void assert<>( bool condition=, condition:bool=, String message="", message:String="", ):void

Asserts that the condition is true. If the condition is false, 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 @GlobalScope.push_error for reporting errors to project developers or add-on users.

An optional message can be shown in addition to the generic "Assertion failed" message. You can use this to provide additional details about why the assertion failed.

Warning: For performance reasons, the code inside 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 assert call. Otherwise, the project will behave differently when exported in release mode.

# 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, "the speed limit is 20") # Show a message.
String char<>( int char=, char:int=, ):String

Returns a single character (as a String) of the given Unicode code point (which is compatible with ASCII code).

a = char(65) # a is "A" a = char(65 + 32) # a is "a" a = char(8364) # a is "€"
Variant convert<>( Variant what=, what:Variant=, int type=, type:int=, ):Variant

Deprecated. Use @GlobalScope.type_convert instead.

Converts what to type in the best way possible. The type uses the Variant.Type values.

var a = [4, 2.5, 1.2] print(a is Array) # Prints true var b = convert(a, TYPE_PACKED_BYTE_ARRAY) print(b) # Prints [4, 2, 1] print(b is Array) # Prints false
Object dict_to_inst<>( Dictionary dictionary=, dictionary:Dictionary=, ):Object

Converts a dictionary (created with inst_to_dict) back to an Object instance. Can be useful for deserializing.

Array get_stack<>():Array

Returns an array of dictionaries representing the current call stack. See also print_stack.

func _ready(): foo() func foo(): bar() func bar(): print(get_stack())

Starting from _ready(), bar() would print:

[{function:bar, line:12, source:res://script.gd}, {function:foo, line:9, source:res://script.gd}, {function:_ready, line:6, source:res://script.gd}]

Note: This function only works if the running instance is connected to a debugging server (i.e. an editor instance). get_stack will not work in projects exported in release mode, or in projects exported in debug mode if not connected to a debugging server.

Note: Calling this function from a Thread is not supported. Doing so will return an empty array.

Dictionary inst_to_dict<>( Object instance=, instance:Object=, ):Dictionary

Returns the passed instance converted to a Dictionary. Can be useful for serializing.

Note: Cannot be used to serialize objects with built-in scripts attached or objects allocated within built-in scripts.

var foo = "bar" func _ready(): var d = inst_to_dict(self) print(d.keys()) print(d.values())

Prints out:

[@subpath, @path, foo] [, res://test.gd, bar]
bool is_instance_of<>( Variant value=, value:Variant=, Variant type=, type:Variant=, ):bool

Returns true if value is an instance of type. The type value must be one of the following:

Unlike the right operand of the is operator, type can be a non-constant value. The is operator supports more features (such as typed arrays) and is more performant. Use the operator instead of this method if you do not need dynamic type checking.

Examples:

print(is_instance_of(a, TYPE_INT)) print(is_instance_of(a, Node)) print(is_instance_of(a, MyClass)) print(is_instance_of(a, MyClass.InnerClass))

Note: If value and/or type are freed objects (see @GlobalScope.is_instance_valid), or type is not one of the above options, this method will raise a runtime error.

See also @GlobalScope.typeof, type_exists, Array.is_same_typed (and other Array methods).

int len<>( Variant var=, var:Variant=, ):int

Returns the length of the given Variant var. The length can be the character count of a String or StringName, the element count of any array type, or the size of a Dictionary. For every other Variant type, a run-time error is generated and execution is stopped.

a = [1, 2, 3, 4] len(a) # Returns 4 b = "Hello!" len(b) # Returns 6
Resource load<>( String path=, path:String=, ):Resource

Returns a Resource from the filesystem located at the absolute path. Unless it's already referenced elsewhere (such as in another script or in the scene), the resource is loaded from disk on function call, which might cause a slight delay, especially when loading large scenes. To avoid unnecessary delays when loading something multiple times, either store the resource in a variable or use preload. This method is equivalent of using ResourceLoader.load with ResourceLoader.CACHE_MODE_REUSE.

Note: 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 current script.

# 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.

Important: The path must be absolute. A relative path will always return null.

This function is a simplified version of ResourceLoader.load, which can be used for more advanced scenarios.

Note: Files have to be imported into the engine first to load them using this function. If you want to load Images at run-time, you may use Image.load. If you want to import audio files, you can use the snippet described in AudioStreamMP3.data.

Note: If ProjectSettings.editor/export/convert_text_resources_to_binary is true, load will not be able to read converted files in an exported project. If you rely on run-time loading of files present within the PCK, set ProjectSettings.editor/export/convert_text_resources_to_binary to false.

Resource preload<>( String path=, path:String=, ):Resource

Returns a Resource from the filesystem located at path. During run-time, the resource is loaded when the script is being parsed. This function effectively acts as a reference to that resource. Note that this function requires path to be a constant String. If you want to load a resource from a dynamic/variable path, use load.

Note: 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 current script.

# Create instance of a scene. var diamond = preload("res://diamond.tscn").instantiate()
void print_debug<>( .=, .:=, ):void

Like @GlobalScope.print, but includes the current stack frame when running with the debugger turned on.

The output in the console may look like the following:

Test print At: res://test.gd:15:_process()

Note: Calling this function from a Thread is not supported. Doing so will instead print the thread ID.

void print_stack<>():void

Prints a stack trace at the current code location. See also get_stack.

The output in the console may look like the following:

Frame 0 - res://test.gd:16 in function '_process'

Note: This function only works if the running instance is connected to a debugging server (i.e. an editor instance). print_stack will not work in projects exported in release mode, or in projects exported in debug mode if not connected to a debugging server.

Note: Calling this function from a Thread is not supported. Doing so will instead print the thread ID.

Array range<>( .=, .:=, ):Array

Returns an array with the given range. range can be called in three ways:

range(n: int): Starts from 0, increases by steps of 1, and stops before n. The argument n is exclusive.

range(b: int, n: int): Starts from b, increases by steps of 1, and stops before n. The arguments b and n are inclusive and exclusive, respectively.

range(b: int, n: int, s: int): Starts from b, increases/decreases by steps of s, and stops before n. The arguments b and n are inclusive and exclusive, respectively. The argument s can be negative, but not 0. If s is 0, an error message is printed.

range converts all arguments to int before processing.

Note: Returns an empty array if no value meets the value constraint (e.g. range(2, 5, -1) or range(5, 5, 1)).

Examples:

print(range(4)) # Prints [0, 1, 2, 3] print(range(2, 5)) # Prints [2, 3, 4] print(range(0, 6, 2)) # Prints [0, 2, 4] print(range(4, 1, -1)) # Prints [4, 3, 2]

To iterate over an Array backwards, use:

var array = [3, 6, 9] for i in range(array.size() - 1, -1, -1): print(array[i])

Output:

9 6 3

To iterate over float, convert them in the loop.

for i in range (3, 0, -1): print(i / 10.0)

Output:

0.3 0.2 0.1
bool type_exists<>( StringName type=, type:StringName=, ):bool

Returns true if the given Object-derived class exists in ClassDB. Note that Variant data types are not registered in ClassDB.

type_exists("Sprite2D") # Returns true type_exists("NonExistentClass") # Returns false



All social media brands are registrated trademarks and belong to their respective owners.





CONTACT IMPRINT TERMS OF USE PRIVACY © ROKOROJI ® 2021 rokojori.com
CONTACT IMPRINT TERMS OF USE PRIVACY © ROKOROJI ® 2021 rokojori.com
We are using cookies on this site. Read more... Wir benutzen Cookies auf dieser Seite. Mehr lesen...