Verse Library verse

06 Fragment

Asynchronously toggles a character's visibility on and off for a set duration.

verse-library/triad-infiltration-making-players-invisible-in-verse/06-fragment.verse

DoFlicker(Victim : agent, Character : fort_character)<suspends> : void =
        # Set the timer for how long they are vulnerable
        if (set PlayerVisibilitySeconds[Victim] = VulnerableSeconds) {}
        else:
            set PlayerVisibilitySeconds[Victim] = VulnerableSeconds

        # Show the character so enemies can see the flicker
        Character.Show()

        # Track elapsed time manually since map subtraction needs a failable set
        var Elapsed : float = 0.0
        loop:
            if (PlayerVisibilitySeconds[Victim] - Elapsed <= 0.0):
                break
            # Toggle: show on even steps, hide on odd steps
            if (Elapsed mod (FlickerRateSeconds * 2.0) < FlickerRateSeconds):
                Character.Show()
            else:
                Character.Hide()
            Sleep(FlickerRateSeconds)
            set Elapsed += FlickerRateSeconds

        # Make sure they are fully invisible again when done
        Character.Hide()

Comments

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