SetFamilyVariable: Difference between revisions
Tayfunwiki (talk | contribs) (Created page with "= <code>SetVariable</code> Method Documentation = == Description == The <code>SetVariable</code> methods allow for setting the value of a private variable for a family based on its name or ID. These methods come in two variants: a non-generic version that sets the value and a generic version that sets the value and returns the updated variable cast to a specified type. == Method Signatures == === SetVariable (Non-Generic) === <syntaxhighlight lang="c#"> public void Se...") |
Tayfunwiki (talk | contribs) No edit summary |
||
Line 20: | Line 20: | ||
=== Non-Generic Usage === | === Non-Generic Usage === | ||
<syntaxhighlight lang="c#"> | <syntaxhighlight lang="c#"> | ||
IM.Player. | IM.Player.Family.SetVariable("booleanVariable", true); | ||
</syntaxhighlight>Sets the value of the <code>booleanVariable</code> to <code>true</code>. | </syntaxhighlight>Sets the value of the <code>booleanVariable</code> to <code>true</code>. | ||
Latest revision as of 07:50, 5 August 2024
SetVariable
Method Documentation
Description
The SetVariable
methods allow for setting the value of a private variable for a family based on its name or ID. These methods come in two variants: a non-generic version that sets the value and a generic version that sets the value and returns the updated variable cast to a specified type.
Method Signatures
SetVariable (Non-Generic)
public void SetVariable(string variableNameOrId, object value)
This method sets the value of the variable with the specified name or ID for the family.
SetVariable (Generic)
public T SetVariable<T>(string variableNameOrId, object value) where T : NVar
This method sets the value of the variable with the specified name or ID for the family and returns the updated variable cast to the specified type T
.
Example Usage
Non-Generic Usage
IM.Player.Family.SetVariable("booleanVariable", true);
Sets the value of the booleanVariable
to true
.
Generic Usage
NBool booleanVar = IM.Player.Family.SetVariable<NBool>("booleanVariable", true);
Debug.Log(booleanVar.Value);
Sets the value of the booleanVariable
to true
and returns the updated variable cast to an NBool
type. The booleanVar.Value
property returns the value as a bool
.
Note: booleanVar.Value
will return the value as a boolean type (bool
).