ReferenceVerse

Map Add Entry

map add entry

Updated

A new pink flamingo wades into the shallows, and instantly the scoreboard updates to track her snack count.

In Verse, a map holds key-value pairs, and adding a new entry is a failable action, so we wrap it in an if statement to safely slot the new flamingo into our tracker.

We declare our map with existing birds, then use set inside an if condition to add Rose and confirm the update succeeded.

Reach for set inside an if block whenever you need to safely add or update a key in your game's dictionary.

var Snacks : [string]int = map{"Pink" => 1, "Coral" => 2}
if (set Snacks["Rose"] = 3):
    Print("Rose gets 3 snacks")

Build your own lesson with map-add-entry

Generate a personalized, compile-checked lesson grounded in this exact reference.

Build a lesson →