Verse Library verse

01 Device

Tracks hits on a target dummy and logs point awards for a shooting gallery.

verse-library/first-island-03-build-a-shooting-gallery-in-fortnite/01-device.verse

using { /Fortnite.com/Devices }
using { /Fortnite.com/Characters }
using { /Fortnite.com/Playspaces }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }

# This is a comment. It explains the code.
# We make a new class that holds our Target Dummy device.
shooting_gallery_manager := class(creative_device):

    # A reference to the Target Dummy placed on the island.
    # Tag this device in the editor so Verse can find it.
    @editable
    My_Target_Dummy : shooting_range_target_device = shooting_range_target_device{}

    # OnBegin runs automatically when the game starts.
    OnBegin<override>()<suspends> : void =
        # When the game starts, we listen for hits.
        My_Target_Dummy.HitEvent.Subscribe(On_Target_Hit)

    # This is a function. It is a set of instructions.
    On_Target_Hit(Arg : tuple()) : void =
        # When the dummy is hit, we give points.
        # We use a score manager or scoring device for points.
        # note: Verse has no built-in Add_Score on player; wire a
        # score_manager_device in the editor and call AddScore() on it,
        # or use the hudcontroller. Here we print to confirm the hit.
        Print("Great Shot! +10 Points")

Comments

    Sign in to vote, comment, or suggest an edit. Sign in