[Solved] Why does "loop = true" not keep animations running?

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
Post Reply
MrChoke
Posts: 324
Joined: Sat Oct 25, 2014 7:20 pm

[Solved] Why does "loop = true" not keep animations running?

Post by MrChoke »

Maybe I do not understand what loop = true means for animations. It doesn't do anything when defined in the object or set with animation:setLoop(true). I am doing a custom healing crystal. One without the "Crystal" component. But I am using everything else from it, including the "spin" animation. However, I cannot keep it spinning. Am I missing something?
Last edited by MrChoke on Tue Oct 27, 2015 10:43 pm, edited 1 time in total.
MrChoke
Posts: 324
Joined: Sat Oct 25, 2014 7:20 pm

[Solved] Re: Why does "loop = true" not keep animations runn

Post by MrChoke »

I still don't know what loop = true does but I solved my problem in another way. I want the spin to keep going. It was easy with my first animationEvent. I use normalizedTime = 1 to do the event at the end of the spin and then I restart it. Very neat.

Code: Select all

...
  {
            class = "Animation",
            animations = {
                spin = "assets/animations/env/healing_crystal_spin.fbx",
            },
            onAnimationEvent = 
                function(self, event)
                    print("in onAnimationEvent", event)
                    if event == "spinEnd" then
                        self:stop()
                        self:play("spin")
                    end
                end,
           },
...

defineAnimationEvent{
    animation = "assets/animations/env/healing_crystal_spin.fbx",
    event = "spinEnd",
    normalizedTime = 1,
}
UPDATE: Answered my own question. "playOnInit" is required for "loop = true" to work. I wanted the crystal to start out disabled and not spinning. Then I click something to activate it and start the spin. Doing it like this does not keep it spinning. You have to do the animationEvent above in order to keep it going.
User avatar
petri
Posts: 1917
Joined: Thu Mar 01, 2012 4:58 pm
Location: Finland

Re: [Solved] Why does "loop = true" not keep animations runn

Post by petri »

AnimationComponent:play() has an optional second argument 'loop' (default false) which you can use to play a looping animation. This should work: play("anim", true)

playOnInit and loop properties are just shortcuts so that a script is not needed for simple cases.
MrChoke
Posts: 324
Joined: Sat Oct 25, 2014 7:20 pm

Re: [Solved] Why does "loop = true" not keep animations runn

Post by MrChoke »

petri wrote:AnimationComponent:play() has an optional second argument 'loop' (default false) which you can use to play a looping animation. This should work: play("anim", true)

playOnInit and loop properties are just shortcuts so that a script is not needed for simple cases.
Oh. Thanks Petri! I will update the wiki with this.
User avatar
Isaac
Posts: 3192
Joined: Fri Mar 02, 2012 10:02 pm

Re: [Solved] Why does "loop = true" not keep animations runn

Post by Isaac »

petri wrote:AnimationComponent:play() has an optional second argument 'loop' (default false) which you can use to play a looping animation. This should work: play("anim", true)

playOnInit and loop properties are just shortcuts so that a script is not needed for simple cases.
Do crystals without the crystal component affect ironman/single save modes?
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: [Solved] Why does "loop = true" not keep animations runn

Post by minmay »

Isaac wrote:
petri wrote:AnimationComponent:play() has an optional second argument 'loop' (default false) which you can use to play a looping animation. This should work: play("anim", true)

playOnInit and loop properties are just shortcuts so that a script is not needed for simple cases.
Do crystals without the crystal component affect ironman/single save modes?
If it doesn't have a CrystalComponent, it's not a crystal, and it won't save the game.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
MrChoke
Posts: 324
Joined: Sat Oct 25, 2014 7:20 pm

Re: [Solved] Why does "loop = true" not keep animations runn

Post by MrChoke »

I have completed my plans with crystals in my dungeon with the help you guys. Basically I have a crystal that uses the "Crystal" component. I changed only the activate and deactivate textures. This means it has a built-in party heal and auto-save. And with that "reload" code from minmay, I have the correct material reloading upon a game load.

Then I have eight other crystals that I will use more like power sources and not as healing crystals. This do not have a crystal component. I re-use the model, the animation, the sound, but with my own colored textures for activated and deactivated. And because there is no crystal component, there is no auto-save and no party heal. Also, because there is no crystal component I can use setMaterialOverrides() instead of setMaterial() to change the textures. setMaterialOverrides() does not need special processing for a reload. The game handles it automatically.
Post Reply