IM.GetVariable
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 usingIM.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.