Verse Library verse

01 Fragment

Locates a named sentry device in the level and binds its elimination event to a custom handling function.

verse-library/team-elimination-game-7-testing-multiplayer-using-the-sentry-device-in-verse/01-fragment.verse

# We define a new Device type. Think of this as a new "Device" in the editor.
# It will hold our logic for managing the sentry.
struct SentryTestDevice: WorldDevice =
    # This is our "Sentry Entity" variable.
    # We'll assign the actual Sentry Device from the level to this variable later.
    SentryEntity: Entity = Invalid

    # This is the "Main" function. It runs when the game starts.
    OnBegin<override>()<suspends>=
        # 1. Find the Sentry in the level.
        # We use FindEntityByDisplayName to grab the specific Sentry we placed.
        # Make sure your Sentry in the editor is named "TestSentry".
        sentry_device := FindEntityByDisplayName<SentryDevice>("TestSentry")
        
        if sentry_device != Invalid:
            # 2. Get the underlying Entity from the Sentry Device.
            # Devices wrap Entities. We need the Entity to access events.
            SentryEntity := sentry_device.GetEntity()
            
            # 3. SUBSCRIBE to the Elimination Event.
            # This is the magic line. We tell Verse:
            # "When this entity is eliminated, run the 'OnSentryDown' function."
            # The `?` means the Agent might be null (e.g., if the sentry died from storm damage).
            _ := SentryEntity.EliminatedEvent.Subscribe(OnSentryDown)
            
            Print("Sentry is live. Come get some.")
        else:
            Print("Error: Could not find 'TestSentry' in the level!")

    # This function runs ONLY when the sentry dies.

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.

Sign in with Discord

Comments

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