SetVariable
SetVariable
Methods in Actor Class
Overview
The SetVariable
methods are designed to update private variables associated with an actor. These methods are crucial in games that require dynamic modification of character attributes, enhancing gameplay and narrative interaction.
Method Variations
- Basic
SetVariable
: Updates a variable's value without type specificity. - Generic
SetVariable
: Updates a variable's value and casts it to a specifiedNVar
type.
Syntax
- Basic:
public void SetVariable(string variableNameOrId, object value)
- Generic:
public T SetVariable<T>(string variableNameOrId, object value) where T : NVar
Parameters
- variableNameOrId (string): The identifier of the variable to update.
- value (object): The new value to assign to the variable.
Description
- Basic: Sets the value of a variable based on its name or ID, applicable to various data types like
NString
,NInt
,NFloat
,NObject
,NBool
, andNEnum
. - Generic: Sets and retrieves the updated value of a variable, cast to a specific
NVar
subclass.
Usage
These methods are used to dynamically adjust character attributes or states, affecting gameplay decisions, character abilities, and narrative progression.
Examples of Usage
- Basic (Updating Health as
NFloat
):public Actor character; string varName = "Health"; float newHealthValue = 75.5f; character.SetVariable(varName, newHealthValue); // The character's health is updated, compatible with NFloat type
- Generic (Adjusting Gold Amount as
NInt
):public Actor character; string varName = "Gold"; int additionalGold = 50; NInt updatedGold = character.SetVariable<NInt>(varName, additionalGold); // The character's gold amount is updated and retrieved as an NInt
Remarks
- The
SetVariable
methods are integral for games with complex character development systems, allowing for real-time updates to various attributes. - These methods enhance gameplay flexibility, enabling characters to adapt to changing scenarios and player decisions.
- The inclusion of different
NVar
types likeNFloat
for health ensures that character data is managed in a way that aligns with its intended use, adding depth to gameplay mechanics.