Family.OnMemberLeave

From Intrigues Wiki
Revision as of 22:43, 4 January 2024 by Tayfunwiki (talk | contribs) (Created page with "== <code>onMemberLeave</code> Event in Family Class == === Overview === The <code>onMemberLeave</code> event in the Family class is invoked when a member leaves the family. This event is particularly important in games where the dynamics of family membership, alliances, and relationships significantly influence the gameplay and story. === Event Definition === <syntaxhighlight lang="c#"> public event Action<Actor> onMemberLeave; </syntaxhighlight> === Description ===...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

onMemberLeave Event in Family Class

Overview

The onMemberLeave event in the Family class is invoked when a member leaves the family. This event is particularly important in games where the dynamics of family membership, alliances, and relationships significantly influence the gameplay and story.

Event Definition

public event Action<Actor> onMemberLeave;

Description

  • Event Type: Action<Actor>
  • Functionality: Activates when a member departs from the family, providing the departing Actor as an argument.

Usage

This event can be used to update family records, alter the narrative, or modify gameplay in response to a change in the family's composition. It's vital in narrative-driven games or those where family ties impact the plot or character interactions.

Example of Usage

public class FamilyMemberDepartureListener : MonoBehaviour {
    void Start() {
        Family playerFamily = IM.Player.Family;
        if (playerFamily != null) {
            playerFamily.onMemberLeave += HandleFamilyMemberDeparture;
        }
    }

    private void HandleFamilyMemberDeparture(Actor departingMember) {
        Debug.Log($"Member {departingMember.Name} has left the player's family.");
        // Additional logic for handling the departure of a family member
    }

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

Description

  • The example shows how to subscribe to and handle the onMemberLeave event.
  • When a member leaves the player's family, HandleFamilyMemberDeparture is called, logging the departure and enabling additional responses or updates.

Remarks

  • It's crucial to unsubscribe from the event in the OnDestroy method to avoid memory leaks or unintended behaviors.
  • The onMemberLeave event ensures that the game accurately reflects changes in family structure, enhancing realism and player engagement.