# This is our main device class.
# It acts like the brain of our scoreboard.
class ScoreTrackerDevice is WorldDevice():
# This is our Map!
# It maps a Player (the Key) to an Integer (the Value).
# We call it PlayerScores.
PlayerScores : [Player]int = map{}
# This function runs when the game starts.
OnBegin<override>()<suspends>: void =
# We start with an empty map.
# It is ready to store scores!
Print("Scoreboard is ready!")
# This function runs when a hit happens.
# We will connect a Trigger to this later.
HandleHit(Attacker: Player, Target: Entity)<suspends>: void =
# Check if the attacker is actually a player.
# If they are not a player, we stop here.
if (Attacker == None):
return
# Look up the current score for this player.
# If the player is not in the map yet,
# the default value for int is 0.
CurrentScore : int = PlayerScores[Attacker]
# Add 1 to their score.
NewScore : int = CurrentScore + 1
Verse Library
verse
01 Fragment
Uses a key-value map to store and update individual player scores when they hit targets.
verse-library/verse-maps-to-look-things-up-by-a-key/01-fragment.verse
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.