The lerp function can help. To fade out you could do:
Every tick: set opacity = lerp(self.opacity, 0, 0.5*dT)
to fade in:
Every tick: set opacity = lerp(self.opacity, 100, 0.5*dT)
To alternate between the two, use a sine function:
Every tick: set opacity = 100* sin(time*50)
construct.net/en