Verse Library verse

01 Fragment

Tracks and updates player scores using a Verse map, defaulting missing keys to zero.

verse-library/key-concepts/01-fragment.verse

# Import the basic Verse library
using /Verse/Engine/1.0

# Create our main script structure
# Think of this as the "Game Instance"
class RevengeTracker is Script():
    # 1. DEFINE THE MAP
    # We are creating a variable called 'RevengeScores'.
    # [Player] is the Key type (the person).
    # int is the Value type (the score).
    # map{} creates an empty container.
    RevengeScores : [Player]int = map{}

    # A function to add points to a player
    # 'player' is the Key we are looking up.
    # 'points' is how many we are adding.
    AddRevengePoint := func(player: Player, points: int):
        # Check if this player already has a locker in our map.
        # If they do, get their current score.
        # If they don't, start them at 0.
        # This is like checking if the locker is empty.
        current_score := if RevengeScores.Contains(player):
            RevengeScores[player] # Get value at this Key
        else:
            0 # Default to 0 if no Key exists yet

        # Add the new points
        new_score := current_score + points

        # UPDATE THE MAP

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