Verse Library verse

01 Device

Stores and resets per-player stats using a weak map whenever a new player joins the session.

verse-library/resetting-persistable-data-for-your-island/01-device.verse

# Import basic Verse tools
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }

# Define the shape of our player data
# This is like a template for the notebook page
player_data := struct:
    Score : int = 0        # Start with 0 points
    Items : []string = array{}  # Start with no items
    Version : int = 1      # The sticker version

# A device class that manages player data resets.
# Place one instance of this device on your island.
player_reset_manager := class(creative_device):

    # This is our shared locker room (weak_map)
    # It holds data for every player who joins
    # note: weak_map keys on player identity; data is cleared if the player leaves.
    var PlayerLockers : weak_map(player, player_data) = map{}

    # Called automatically by UEFN when the device starts
    OnBegin<override>()<suspends> : void =
        # Subscribe to the player-joined event for this session
        GetPlayspace().PlayerAddedEvent().Subscribe(OnPlayerJoined)

    # This function resets a player's data
    # Think of it as erasing the notebook page
    ResetPlayerData(P : player) : void =
        # Create a fresh, empty data template

Sign in free to read the full source 🌴

This Verse Library file is members-only. Create a free account to view the complete source and download the .verse file.

Sign in with Discord

Comments

    Sign in to vote, comment, or suggest an edit. Sign in