# Declare the variable at the top of your script
# This variable lives with this specific coin
var CoinsCollected : int = 0
# This function runs when the coin is picked up
OnPickedUp[Source : Player] = () =>
# Add 1 to the variable
set CoinsCollected += 1
# Print the new value
print("I collected a coin! Total: ", CoinsCollected)
Verse Library
verse
02 Fragment
Increments a global coin variable when a player picks up an item, useful for basic score tracking.
verse-library/declaring-a-variable/02-fragment.verse