Variant
Polymophic type. Used primarily for storing game variables.
Automatically morphs between bool, int, float, double, string, Vector2, Vector3 and Vector4 based on use.
Remarks: Can be assigned implicitly with all compatible types, but must be explicitly cast (using "As"-methods) when value is read or compared.
Related articles:Constructors
Variant()
Variant(const Variant& other)
Variant(bool value)
Variant(int value)
Variant(float value)
Variant(double value)
Variant(const string &in value)
Variant(const Vector2 &in value)
Variant(const Vector3 &in value)
Variant(const Vector4 &in value)
Methods
string AsString() const
Returns value as a string.
bool AsBool() const
Returns value as a boolean.
int AsInt() const
Returns value as an integer.
float AsFloat() const
Returns value as a float.
double AsDouble() const
Returns value as a double.
Vector2 AsVector2() const
Returns value as a Vector2.
Vector3 AsVector3() const
Returns value as a Vector3.
Vector3 AsVector4() const
Returns value as a Vector4.
Sample
Variant var; var = 1.0f; float f = var.AsFloat(); var = Vector2(1,2); Vector2 v = var.AsVector2(); $Points = 100; Print("Points = " + $Points.AsString());
Warning: Variants will morph depending on which type is assigned to it. This can cause data loss in some cases.
Variant var = "Hello"; // var is "Hello" var = Vector3(1,2,3); // var is (1,2,3) var *= 2.0f; // var is (2,4,6) var += Vector2(1,2); // var is (3,6) var -= 2; // var is (1) var += "3,1"; // var is "13,1"