GetVariable

From Intrigues Wiki
Revision as of 07:57, 24 December 2023 by Tayfunwiki (talk | contribs) (Created page with "== <code>GetVariable</code> Methods in Actor Class == === Overview === The <code>GetVariable</code> methods in the <code>Actor</code> 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): Ret...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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

  1. GetVariable (Generic Type): Retrieves a private variable and casts it to a specified type.
  2. GetVariable (NVar Type): Retrieves a private variable as a general NVar object.

Syntax

  1. Generic Type:
    public T GetVariable<T>(string variableNameOrId) where T : NVar
    
  2. 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, or NEnum.
  • 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

  1. 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
    
  2. 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.