Verse Library verse

02 Fragment

Plays a character emote or animation clip and suspends until it finishes or errors.

verse-library/verse-play-animation-on-character/02-fragment.verse

# WAIT FOR THE ANIMATION TO FINISH, then react to HOW it ended.
#
# Play() returns instantly; PlayAndAwait() SUSPENDS until the clip ends and
# hands back a play_animation_result enum telling you the outcome. Because it
# suspends, call it from a <suspends> context -- here we spawn one so the
# button handler itself stays non-suspending.
PlayThenReact(Presser : agent)<suspends> : void =
    if:
        Sequence := EmoteAnim?
        Character := Presser.GetFortCharacter[]
        Controller := Character.GetPlayAnimationController[]
    then:
        # Suspends right here until the clip completes or is interrupted.
        Result := Controller.PlayAndAwait(Sequence, ?PlayCount := 1.0)
        case (Result):
            play_animation_result.Completed   => Print("Finished cleanly")
            play_animation_result.Interrupted => Print("Something interrupted it")
            play_animation_result.Error       => Print("Playback errored")

Comments

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