Verse Library verse

02 Fragment

Binds a custom function to a spawner device event to trigger logging or effects on entity creation.

verse-library/subscribing-to-reinforcement-spawned-event/02-fragment.verse

# 1. Define the function that will handle the event.
# This is the "Explosion" in our tripwire analogy.
OnReinforcementSpawned(SpawnedGuard: Actor) :=
    # Print a message to the chat/log so we know it worked
    Print("A new reinforcement just spawned!")
    
    # Optional: Do something visual, like flashing the screen or playing a sound
    # For now, let's just print the location of the new guard
    Print("Guard spawned at: " + SpawnedGuard.GetTransform().Location)

# 2. The Main Entry Point. This runs when the game starts.
OnBegin<override>()<suspends> : void =
    # Find our specific spawner by name.
    # In a real map, you'd get this from a collection or variable.
    set MySpawner : GuardReinforcementSpawnerDevice = GetPlayspace().GetDevice("MyReinforcementSpawner")
    
    # 3. SUBSCRIBE to the event.
    # This tells Verse: "When MySpawner spawns something, run OnReinforcementSpawned."
    MySpawner.SpawnedEvent.Subscribe(OnReinforcementSpawned)
    
    # Start the game loop or any other logic
    Print("Script is listening for reinforcements...")

Comments

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