IM.GetVariable

From Intrigues Wiki
Revision as of 16:16, 4 January 2024 by Tayfunwiki (talk | contribs) (Created page with "== <code>GetVariable</code> Method in IM Class == === Overview === The <code>GetVariable</code> method in the IM (Intrigue Manager) class retrieves a public variable based on its name or ID. === Syntax === <syntaxhighlight lang="c#"> public static NVar GetVariable(string variableNameOrId) </syntaxhighlight> === Parameters === * <code>variableNameOrId</code>: A string representing either the name or the ID of the desired variable. === Functionality === * Searches th...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

GetVariable Method in IM Class

Overview

The GetVariable method in the IM (Intrigue Manager) class retrieves a public variable based on its name or ID.

Syntax

public static NVar GetVariable(string variableNameOrId)

Parameters

  • variableNameOrId: A string representing either the name or the ID of the desired variable.

Functionality

  • Searches the game's variable collection for a variable that matches the provided name or ID.
  • Returns the corresponding NVar object if found.
  • If no matching variable is found, returns a new NString object with a placeholder indicating the variable's absence.

Usage

Used for dynamic access to public variables within the game, enabling retrieval and manipulation of game data and logic based on variable identifiers.

Example of Usage

public class VariableManager : MonoBehaviour {
    public string variableKey;

    public void DisplayVariableValue() {
        NVar variable = IM.GetVariable(variableKey);
        Debug.Log($"Value of variable '{variableKey}': {variable.value}");
    }
}

Description

  • DisplayVariableValue: Demonstrates fetching a variable using IM.GetVariable and logging its value.

Remarks

  • Essential in games using a data-driven approach for controlling game behavior or storing state.
  • Ensures effective access and utilization of variables for enhanced game mechanics.