Difference between revisions of "IC Python API:RLPy RVariant"

From Reallusion Wiki!
Jump to: navigation, search
m
m
Line 5: Line 5:
 
== Description ==
 
== Description ==
  
This class acts like an union for common data types. A RVariant object holds a single value of a specified type T at a time. You can use GetType() to find out what type the variant holds, and get its value by one of the ToT() functions (e.g., ToInt32()). Currently, there are two types supported: float and int.
+
This class acts like an union for common data types. A [[IC_Python_API:RLPy_RVariant|RVariant]]object holds a single value of a specified type T at a time. You can use [[#GetType ( self )|GetType]] to find out what type the variant holds, and get its value by one of the ToT() functions, e.g. [[#ToInt32 ( self, pSucess = None )|ToInt32]]. Currently, there are two types supported: float and int.
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
x = RLPy.RVariant(-10)
 
x = RLPy.RVariant(-10)
 
print(x.GetType() == RLPy.RVariant.Int32)          #true
 
print(x.GetType() == RLPy.RVariant.Int32)          #true
Line 25: Line 25:
 
=== GetType ( self ) ===
 
=== GetType ( self ) ===
  
Get type of a RVariant object.
+
Get type of this [[IC_Python_API:RLPy_RVariant|RVariant]] object.
  
 
==== Returns ====
 
==== Returns ====
:Type of a RVariant object - int  
+
:Type of this [[IC_Python_API:RLPy_RVariant|RVariant]] object - int  
 
:*RLPy.RVariant.Float
 
:*RLPy.RVariant.Float
 
:*RLPy.RVariant.Int32
 
:*RLPy.RVariant.Int32
 
:*RLPy.RVariantUInt32
 
:*RLPy.RVariantUInt32
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
x = RLPy.RVariant(-10)
 
x = RLPy.RVariant(-10)
 
print(x.GetType() == RLPy.RVariant.Int32)          #true
 
print(x.GetType() == RLPy.RVariant.Int32)          #true
Line 42: Line 42:
 
Convert to float.
 
Convert to float.
  
See Also: [[#ToInt32 ( self, pSucess = None )|ToInt32 ( self, pSucess = None )]], [[#ToUInt32( self, pSucess = None )|ToUInt32( self, pSucess = None )]]
+
See Also: [[#ToInt32 ( self, pSucess = None )|ToInt32]], [[#ToUInt32( self, pSucess = None )|ToUInt32]]
  
 
==== Parameters ====
 
==== Parameters ====
:pSucess [IN] success or not - bool
+
:'''pSucess''' [IN] success or not - bool
  
 
==== Returns ====
 
==== Returns ====
 
:Value after conversion - float
 
:Value after conversion - float
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
x = RLPy.RVariant(-10)  
 
x = RLPy.RVariant(-10)  
 
f = x.ToFloat()
 
f = x.ToFloat()
Line 60: Line 60:
 
Convert to int32_t.
 
Convert to int32_t.
  
See Also: [[#ToFloat ( self, pSucess = None )|ToFloat ( self, pSucess = None )]], [[#ToUInt32( self, pSucess = None )|ToUInt32( self, pSucess = None )]]
+
See Also: [[#ToFloat ( self, pSucess = None )|ToFloat]], [[#ToUInt32( self, pSucess = None )|ToUInt32]]
  
 
==== Parameters ====
 
==== Parameters ====
:pSucess [IN] success or not - bool
+
:'''pSucess''' [IN] success or not - bool
  
 
==== Returns ====
 
==== Returns ====
 
:Signed integer value after conversion - int32
 
:Signed integer value after conversion - int32
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
f = RLPy.RVariant(-10.0)  
 
f = RLPy.RVariant(-10.0)  
 
x = f.ToInt32()
 
x = f.ToInt32()
Line 78: Line 78:
 
Convert to uint32_t.
 
Convert to uint32_t.
  
See Also: [[#ToFloat ( self, pSucess = None )|ToFloat ( self, pSucess = None )]], [[#ToInt32 ( self, pSucess = None )|ToInt32 ( self, pSucess = None )]]
+
See Also: [[#ToFloat ( self, pSucess = None )|ToFloat]], [[#ToInt32 ( self, pSucess = None )|ToInt32]]
  
 
==== Parameters ====
 
==== Parameters ====
:pSucess [IN] success or not - bool
+
:'''pSucess''' [IN] success or not - bool
  
 
==== Returns ====
 
==== Returns ====
 
:Unsigned integer value after conversion - uint32
 
:Unsigned integer value after conversion - uint32
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
f = RLPy.RVariant(10.0)  
 
f = RLPy.RVariant(10.0)  
 
x = f.ToUInt32()
 
x = f.ToUInt32()
 
print(x)  
 
print(x)  
 
</syntaxhighlight>
 
</syntaxhighlight>

Revision as of 19:22, 8 April 2020

Main article: Modules.
Last modified: 04/8/2020

Description

This class acts like an union for common data types. A RVariantobject holds a single value of a specified type T at a time. You can use GetType to find out what type the variant holds, and get its value by one of the ToT() functions, e.g. ToInt32. Currently, there are two types supported: float and int.

x = RLPy.RVariant(-10)
print(x.GetType() == RLPy.RVariant.Int32)           #true
 
f = x.ToFloat()
print(f)                                            #-10.0
 
y = RLPy.RVariant(10.0)
print(y.GetType() == RLPy.RVariant.Float)           #true
 
n = x.ToInt32()
print(n)

Member Functions

GetType ( self )

Get type of this RVariant object.

Returns

Type of this RVariant object - int
  • RLPy.RVariant.Float
  • RLPy.RVariant.Int32
  • RLPy.RVariantUInt32
x = RLPy.RVariant(-10)
print(x.GetType() == RLPy.RVariant.Int32)           #true

ToFloat ( self, pSucess = None )

Convert to float.

See Also: ToInt32, ToUInt32

Parameters

pSucess [IN] success or not - bool

Returns

Value after conversion - float
x = RLPy.RVariant(-10) 
f = x.ToFloat()
print(f)

ToInt32 ( self, pSucess = None )

Convert to int32_t.

See Also: ToFloat, ToUInt32

Parameters

pSucess [IN] success or not - bool

Returns

Signed integer value after conversion - int32
f = RLPy.RVariant(-10.0) 
x = f.ToInt32()
print(x)

ToUInt32( self, pSucess = None )

Convert to uint32_t.

See Also: ToFloat, ToInt32

Parameters

pSucess [IN] success or not - bool

Returns

Unsigned integer value after conversion - uint32
f = RLPy.RVariant(10.0) 
x = f.ToUInt32()
print(x)