|
@@ -17,21 +17,21 @@
|
|
- VisualScript tracks properties inside Variants as well, but it also uses static typing. The GUI interface enforces that properties have a particular type that doesn't change over time.
|
|
- VisualScript tracks properties inside Variants as well, but it also uses static typing. The GUI interface enforces that properties have a particular type that doesn't change over time.
|
|
- C# is statically typed, but uses the Mono [code]object[/code] type in place of Godot's Variant class when it needs to represent a dynamic value. [code]object[/code] is the Mono runtime's equivalent of the same concept.
|
|
- C# is statically typed, but uses the Mono [code]object[/code] type in place of Godot's Variant class when it needs to represent a dynamic value. [code]object[/code] is the Mono runtime's equivalent of the same concept.
|
|
- The statically-typed language NativeScript C++ does not define a built-in Variant-like class. Godot's GDNative bindings provide their own godot::Variant class for users; Any point at which the C++ code starts interacting with the Godot runtime is a place where you might have to start wrapping data inside Variant objects.
|
|
- The statically-typed language NativeScript C++ does not define a built-in Variant-like class. Godot's GDNative bindings provide their own godot::Variant class for users; Any point at which the C++ code starts interacting with the Godot runtime is a place where you might have to start wrapping data inside Variant objects.
|
|
- The global [member @GDScript.typeof] function returns the enumerated value of the Variant type stored in the current variable. These correspond to [code]TYPE_*[/code] constants in the [@GlobalScope] docs.
|
|
|
|
|
|
+ The global [method @GDScript.typeof] function returns the enumerated value of the Variant type stored in the current variable. These correspond to [code]TYPE_*[/code] constants in the [@GlobalScope] docs.
|
|
[codeblock]
|
|
[codeblock]
|
|
var foo = 2
|
|
var foo = 2
|
|
match typeof(foo):
|
|
match typeof(foo):
|
|
- TYPE_NIL:
|
|
|
|
- print("foo is null!")
|
|
|
|
- TYPE_INTEGER:
|
|
|
|
- print("foo is an integer!")
|
|
|
|
- TYPE_OBJECT:
|
|
|
|
- # Note that Objects are their own special category.
|
|
|
|
- # To get the name of the underlying Object type, you need the `get_class()` method.
|
|
|
|
- print("foo is a(n) %s" % foo.get_class()) # inject the class name into a formatted string.
|
|
|
|
- # Note also that there is not yet any way to get a script's `class_name` string easily.
|
|
|
|
- # To fetch that value, you need to dig deeply into a hidden ProjectSettings setting: an Array of Dictionaries called "_global_script_classes".
|
|
|
|
- # Open your project.godot file to see it up close.
|
|
|
|
|
|
+ TYPE_NIL:
|
|
|
|
+ print("foo is null")
|
|
|
|
+ TYPE_INTEGER:
|
|
|
|
+ print("foo is an integer")
|
|
|
|
+ TYPE_OBJECT:
|
|
|
|
+ # Note that Objects are their own special category.
|
|
|
|
+ # To get the name of the underlying Object type, you need the `get_class()` method.
|
|
|
|
+ print("foo is a(n) %s" % foo.get_class()) # inject the class name into a formatted string.
|
|
|
|
+ # Note also that there is not yet any way to get a script's `class_name` string easily.
|
|
|
|
+ # To fetch that value, you need to dig deeply into a hidden ProjectSettings setting: an Array of Dictionaries called "_global_script_classes".
|
|
|
|
+ # Open your project.godot file to see it up close.
|
|
[/codeblock]
|
|
[/codeblock]
|
|
A Variant takes up only 20 bytes and can store almost any engine datatype inside of it. Variants are rarely used to hold information for long periods of time. Instead, they are used mainly for communication, editing, serialization and moving data around.
|
|
A Variant takes up only 20 bytes and can store almost any engine datatype inside of it. Variants are rarely used to hold information for long periods of time. Instead, they are used mainly for communication, editing, serialization and moving data around.
|
|
Godot has specifically invested in making its Variant class as flexible as possible; so much so that it is used for a multitude of operations to facilitate communication between all of Godot's systems.
|
|
Godot has specifically invested in making its Variant class as flexible as possible; so much so that it is used for a multitude of operations to facilitate communication between all of Godot's systems.
|