GetVariable
GetVariable
Methods in Actor Class
Overview
The GetVariable
methods in the Actor
class are used to retrieve private variables of different types from an actor. These methods are essential in games where actors have customizable attributes or states stored as variables.
Method Variations
- GetVariable (Generic Type): Retrieves a private variable and casts it to a specified type.
- GetVariable (NVar Type): Retrieves a private variable as a general
NVar
object.
Syntax
- Generic Type:
public T GetVariable<T>(string variableNameOrId) where T : NVar
- NVar Type:
public T GetVariable<T>(string variableNameOrId) where T : NVar
Parameters
- variableNameOrId (string): The name or ID of the variable to be retrieved.
Description
- Generic Type: Retrieves a variable and casts it to a specific type, such as
NString
,NInt
,NFloat
,NObject
,NBool
, orNEnum
. - NVar Type: Retrieves a variable as a general
NVar
object without specifying the type.
Usage
Used to access and utilize various actor-specific data, enhancing gameplay flexibility and character customization.
Examples of Usage
- Generic Type (NInt for Gold Amount):
public Actor character; string varName = "Gold"; NInt gold = character.GetVariable<NInt>(varName); // Use 'gold' for logic related to the character's gold amount
- NVar Type (Generic Variable Retrieval):
public Actor character; string varName = "Health"; NVar healthVar = character.GetVariable(varName); // Use 'healthVar' for generic health-related logic
Remarks
- The
GetVariable
methods provide crucial functionality for dynamic game mechanics where characters' attributes and states influence gameplay and narrative. - The ability to retrieve variables in both typed and untyped forms offers flexibility and type safety, catering to various gameplay scenarios.
- These methods are particularly useful in RPGs, simulation games, and any game that requires in-depth character attribute management.