OnFamilyNameChanged

From Intrigues Wiki
Revision as of 21:39, 4 January 2024 by Tayfunwiki (talk | contribs) (Created page with "== <code>onFamilyNameChanged</code> Event in Family Class == === Overview === The <code>onFamilyNameChanged</code> event in the Family class is triggered when there is a change in the name of a family. This event is particularly important in games where family identity and legacy play a significant role, as it allows for dynamic updates and responses to changes in family nomenclature. === Event Definition === <syntaxhighlight lang="c#"> public event Action<string> onFa...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

onFamilyNameChanged Event in Family Class

Overview

The onFamilyNameChanged event in the Family class is triggered when there is a change in the name of a family. This event is particularly important in games where family identity and legacy play a significant role, as it allows for dynamic updates and responses to changes in family nomenclature.

Event Definition

public event Action<string> onFamilyNameChanged;

Description

  • Event Type: Action<string>
  • Functionality: Notifies when the family's name is changed, passing the new name as a parameter.

Usage

This event can be utilized to update UI elements, trigger narrative changes, or adjust game mechanics in response to a change in a family's name. It's useful in scenarios where the family name is tied to reputations, alliances, land holdings, or other in-game factors.

Example of Usage

public class FamilyNameListener : MonoBehaviour {
    void Start() {
        Family playerFamily = IM.Player.Family;
        if (playerFamily != null) {
            playerFamily.onFamilyNameChanged += HandleFamilyNameChange;
        }
    }

    private void HandleFamilyNameChange(string oldName) {
        Debug.Log($"The player's family name has been changed to: {IM.Player.Family.FamilyName}, Old name: {oldName}");
        // Additional logic to handle the name change
    }

    void OnDestroy() {
        if (IM.Player.Family != null) {
            IM.Player.Family.onFamilyNameChanged -= HandleFamilyNameChange;
        }
    }
}

Description

  • This example demonstrates how to subscribe to the onFamilyNameChanged event and handle it.
  • When the family's name changes, HandleFamilyNameChange is called, logging the new name and potentially triggering other related actions.

Remarks

  • It's important to unsubscribe from the event when the object is destroyed to prevent memory leaks or unwanted behavior.
  • The onFamilyNameChanged event helps maintain consistency and accuracy in the game's narrative and UI, reflecting changes in family identity in real-time.