Build a Tower Defense Turret with Verse
verse-library
turret_score_manager := class(creative_device):
# We reference our Automated Turret device here.
# Drag your placed device onto this property in the editor.
@editable
Turret : automated_turret_device = automated_turret_device{}
# This is a Variable.
# It holds the current score.
# It starts at zero.
var Score : int = 0
# OnBegin runs automatically when the game starts.
OnBegin<override>()<suspends> : void =
# We wait for an Event.
# DestroyedEvent fires when the turret is destroyed, or we can use TargetFoundEvent.
# This means an enemy was hit by this turret.
loop:
# Block here until the turret finds a target (eliminates someone).
Turret.TargetFoundEvent.Await()
# When the event happens...
# Add one to our score.
set Score = Score + 1
# Print the score to the screen.
# This helps us see it working.
Print("Score: {Score}")