SetVariable

From Intrigues Wiki
Revision as of 08:03, 24 December 2023 by Tayfunwiki (talk | contribs) (Created page with "== <code>SetVariable</code> Methods in Actor Class == === Overview === The <code>SetVariable</code> 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 <code>SetVariable</code>: Updates a variable's value without type specificity. # Generic <code>SetVariable</code>: Updates...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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

  1. Basic SetVariable: Updates a variable's value without type specificity.
  2. Generic SetVariable: Updates a variable's value and casts it to a specified NVar type.

Syntax

  1. Basic:
    public void SetVariable(string variableNameOrId, object value)
    
  2. 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, and NEnum.
  • 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

  1. 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
    
  2. 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 like NFloat for health ensures that character data is managed in a way that aligns with its intended use, adding depth to gameplay mechanics.