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

From Reallusion Wiki!
Jump to: navigation, search
m
m
 
(One intermediate revision by the same user not shown)
Line 29: Line 29:
 
==== Returns ====
 
==== Returns ====
 
:Type of a RVariant object - int  
 
:Type of a RVariant object - int  
:RLPy.RVariant.Float, RLPy.RVariant.Int32, or RLPy.RVariantUInt32
+
:*RLPy.RVariant.Float
 +
:*RLPy.RVariant.Int32
 +
:*RLPy.RVariantUInt32
  
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">

Latest revision as of 00:49, 23 March 2020

Main article: Modules. Last modified: 03/23/2020

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.

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 a RVariant object.

Returns

Type of a 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 ( self, pSucess = None ), ToUInt32( self, pSucess = None )

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 ( self, pSucess = None ), ToUInt32( self, pSucess = None )

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 ( self, pSucess = None ), ToInt32 ( self, pSucess = None )

Parameters

pSucess [IN] success or not - bool

Returns

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