Linking animations

I have an alien that when it dies I want it to first grow larger then to shrink and to fade away.

So in the function that it gets killed in I call…

go.animate(go.get_id(), "scale", go.PLAYBACK_ONCE_FORWARD, vmath.vector3(1.6,1.6,1.6), go.EASING_LINEAR, 1.5,0, implode)

This works and causes it to grow.
Above that function I put the implode local function which is supposed to make it shrink and fade away.

local function implode(self)
	print("implode")
	go.animate(self.id, "scale", go.PLAYBACK_ONCE_FORWARD, vmath.vector3(0.4,0.4,0.4), go.EASING_LINEAR, 2,0, go.delete())
	go.animate(self.id, "tint.w", go.PLAYBACK_ONCE_FORWARD, 0.3, go.EASING_LINEAR ,2,0)					
end

I also tried go.get_id() instead of self.id… neither the shrink or the tint are working.

Thanks for any help.

/Ash

On death you want it to implode and when the implode is done you want it to “shrink” and “fade out” at the same time?

I want it to expand and then after that to shrink and fadeout together.
Below is the code in more detail…

local function implode(self)
	print(“implode”)
	go.animate(self.id, “scale”, go.PLAYBACK_ONCE_FORWARD, vmath.vector3(0.4,0.4,0.4), go.EASING_LINEAR, 2,0, go.delete())
	go.animate(self.id, “tint.w”, go.PLAYBACK_ONCE_FORWARD, 0.3, go.EASING_LINEAR ,2,0)
end

local function hit(self)
	self.health = self.health -10
	if(self.health<0)then
		if(self.dead== false)then 
			self.dead = true
			sound.play("/sounds#explode")		
			go.animate(go.get_id(), "scale", go.PLAYBACK_ONCE_FORWARD, vmath.vector3(1.6,1.6,1.6), go.EASING_LINEAR, 1.5,0, implode())
		end
	end
end

It’s super hard to read the code without the formatting

So what you have here is the classic problem of calling a function instead of refereeing to it.

go.animate(self.id, “scale”, go.PLAYBACK_ONCE_FORWARD, vmath.vector3(0.4,0.4,0.4), go.EASING_LINEAR, 2,0, go.delete())

If you notice this actually says go.delete() notice the (). That makes it into a function call which will be triggered imitatively. So it deletes it as soon as it sees it. That’s why it says it can’t find the object with the id.

The fix is to simply remove the ()

go.animate(self.id, “scale”, go.PLAYBACK_ONCE_FORWARD, vmath.vector3(0.4,0.4,0.4), go.EASING_LINEAR, 2,0, go.delete)
2 Likes

hmm… ok so a school boy error there .

Still doesnt seem to work …

local function implode(self)
	go.animate(self.id, "scale", go.PLAYBACK_LOOP_BACKWARD, vmath.vector3(0.4,0.4,0.4) ,go.EASING_LINEAR, 2 ,0, go.delete)
	go.animate(self.id, "tint.w", go.PLAYBACK_ONCE_FORWARD, 0.3, go.EASING_LINEAR ,2,0)
end

local function hit(self)
	self.health = self.health -10
	if(self.health<0)then
		if(self.dead== false)then 
			self.dead = true
			sound.play("/sounds#explode")		
			go.animate(go.get_id(), "scale", go.PLAYBACK_ONCE_FORWARD, vmath.vector3(1.6,1.6,1.6), go.EASING_LINEAR, 1.5,0, implode)
		end
	end
end

Error on the first “scale” call…
ERROR:SCRIPT: attempt to concatenate a function value
stack traceback:
[C]: in function ‘animate’
/assets/alien/alien.script:22: in function </assets/alien/alien.script:21>

Almost. Note that go.delete() takes two arguments, id and recursive. The go.animate() callback will pass self, url and property. This may not play nicely with go.delete(). You need to wrap in an anonymous function:

    go.animate(self.id, "scale", go.PLAYBACK_ONCE_FORWARD, vmath.vector3(0.4,0.4,0.4), go.EASING_LINEAR, 2,0, function(self, url, property)
        go.delete()
    end)
2 Likes