Stop animation in specific frame

  • #20, by zurikTuesday, 26. February, 19:44 2 months ago
    Hi. I found this post and trying to do the same, but obviously I am doing something wrong.
    To play an animation and stop it on a specific frame. For example if I am animating a Battery or a Fuel status bar. I put that script in the Script tab, but how do I run the function? From the animation frames or action parts?

    Thanks

    Newbie

    19 Posts


  • #21, by NigecTuesday, 26. February, 20:28 2 months ago
    From the action part, Execute Script is what you are looking for
    setFrames(anim, a, b)
    anim = your animation
    a = start frame
    b - end frame

    Mine doesn't have the anim but still the same idea

    Great Poster

    469 Posts

  • #22, by NigecTuesday, 26. February, 20:35 2 months ago
    if you are interested, this uses animation to do a myth style turn, also a combination lock

    Great Poster

    469 Posts

  • #23, by zurikTuesday, 26. February, 21:16 2 months ago
    Thanks. I unclick the definition script box, paste this code, but nothing happens.
    When I just play the animation with "play animation" it plays, but I need to stop it.

    function setAnimFrames(anim, a, b)
     if b == nil then b = a end -- fallback in case only a value was entered
     -- + --
     ActiveAnimations[anim].AnimationFirstFrame = a
     ActiveAnimations[anim].AnimationLastFrame = b
    end

    and put 
    setAnimFrames("Animation4", 2, 12)
    to the Action Part

    I hope I am making a super stupid mistake grin

    Thanks for your help

    Newbie

    19 Posts

  • #24, by AFRLmeTuesday, 26. February, 23:21 2 months ago
    The function should be in a definition type script.

    Definition scripts are run at game launch, thus they are good for declaring functions & variables.

    Execution scripts (definition unticked) will only work when you manually call the script via the call script action part. These should only be used when functions aren't needed, & even then should only really be used if the script you write has a lot of lines of code or you want to call it multiple times throughout the game.

    For the most part you should only really be using definition type scripts & execute a script action parts.

    Now in regards to what you wrote:

    setAnimFrames("Animation4", 2, 12)
    1

    What you are doing here is forcing animation "Animation4" to loop between frames 2 & 12. The animation needs to be set to loop infinitely otherwise it won't work, as the animation will automatically end & hide when it reaches the final frame. In regards to forcing an animation to be locked to a single frame you just need to enter the same frame number into the function twice - taking into account that animations start from frame 1 & not 0 when it comes to Lua script...
    setAnimFrames("example", 12, 12) -- force animation "example" to loop frame 12
    1
    2

    Imperator

    6516 Posts

  • #25, by zurikWednesday, 27. February, 14:06 2 months ago
    I am sorry, guys. I guess I am still doing something wrong. Here is the screenshot from all the parts regarding my Animation. Can you see, what's wrong? This should show the frame 5 from the animation, right? It doesn't. How should the animation settings be? Loop, Set pause etc?
    Thank you

    Newbie

    19 Posts

  • #26, by esmeraldaWednesday, 27. February, 14:21 2 months ago
    Like AFRLme said,  loop should be set to infinite, else the animation will only show once (or how often you set it to loop)
    Pauses don't matter that much when only showing one frame.

    Great Poster

    333 Posts

  • #27, by zurikWednesday, 27. February, 15:44 2 months ago
    Thanks. Weird - nothing happens. When I "Play animation" with Action Part it works perfectly, but not with the script. I will try to set everything again, but obviously I am doing something wrong.

    Newbie

    19 Posts

  • #28, by AFRLmeWednesday, 27. February, 19:12 2 months ago
    Eh? are you trying to start/play the animation with my setAnimFrames() function? that's not what it is for, at all. It's for forcing an already playing animation to loop between a set range of frames. Play the animation or assign the animation as the default animation of the scene object via the properties section of the scene object. Execute the function at any point while the animation is already playing.

    Imperator

    6516 Posts

  • #29, by zurikThursday, 28. February, 16:53 2 months ago
    Hi. What I am trying to do is to play the animation from A to B and stop in on the B frame. And I can't make it whatever I try grin

    Newbie

    19 Posts

  • #30, by sebastianThursday, 28. February, 17:13 2 months ago
    Hi. What I am trying to do is to play the animation from A to B and stop in on the B frame. And I can't make it whatever I try grin

    In Frame B, edit that frame and add an "execute a script "action part.
    Enter this inside:

     ActiveAnimations["animation name"].FirstFrame = b
     ActiveAnimations["animation name"].LastFrame = b
    1
    2

    b = number of frame b

    Thread Captain

    2302 Posts

Write post