Stop animation in specific frame

  • #20, by zurikTuesday, 26. February 2019, 19:44 5 years 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

    40 Posts


  • #21, by NigecTuesday, 26. February 2019, 20:28 5 years 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

    Key Killer

    627 Posts

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

    Key Killer

    627 Posts

  • #23, by zurikTuesday, 26. February 2019, 21:16 5 years 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

    40 Posts

  • #24, by afrlmeTuesday, 26. February 2019, 23:21 5 years 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)

    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
    

    Imperator

    7278 Posts

  • #25, by zurikWednesday, 27. February 2019, 14:06 5 years 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

    40 Posts

  • #26, by esmeraldaWednesday, 27. February 2019, 14:21 5 years 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.

    Key Killer

    513 Posts

  • #27, by zurikWednesday, 27. February 2019, 15:44 5 years 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

    40 Posts

  • #28, by afrlmeWednesday, 27. February 2019, 19:12 5 years 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

    7278 Posts

  • #29, by zurikThursday, 28. February 2019, 16:53 5 years 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

    40 Posts

  • #30, by sebastianThursday, 28. February 2019, 17:13 5 years 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

    b = number of frame b

    Thread Captain

    2346 Posts