Animated Background

I’m working on an instrument and I’m trying to implement an animated background. I’ve tried doing this a number of ways and I’m hoping someone can nudge me in the right direction on how to achieve this.

Basically on initialization, I want the background to start animating. I have a 20 frame bitmap png file that I’m using. But so far I haven’t been able to get it to function. I’ve lost track of all my attempts and the last thing I’ve done is just try to use the Animation Script Template Example altering the script to achieve this but to no avail. Here’s what I have:
The bitmap is going to the png.
The Animation Script Template is set to 20 frames and an appropriate frame duration.
I’ve tried altering the script a bit:

inc = 0.1
out =0

defineParameter {
  name = 'out',
  default = 0,
  min = 0,
  max = 1
}
defineParameter {
  name = "frames",
  default = 20,
  min =1,
  max =1000,
  type = "integer",
  onChanged = function()
    inc = 1 / frames
  end
}
defineParameter {
  name = "frameDuration",
  default = 1000 / 24,
  min =20,
  max = 10000,
  type = "integer"
}
function animate()
  while true do
    out = (out + inc) % 1
    wait(frameDuration)
  end
end
function onLoadFinished()
  runAsync(animate)
end

Any and all help is much appreciated!
Thanks!

If you try like this?

frameRate = 24
frameDuration = 1000 / frameRate
lastFrame = 20

defineParameter("animation", nil, 0, 0, lastFrame, 1)
defineParameter("on", nil, true, function() animate() end)

function animate()
	while on do
		local frame = animation + 1
		if frame > lastFrame then
			frame = 0
		end
		animation = frame
		wait(frameDuration)
	end
end

function onLoad()
	animate()
end

If I paste this code into the Animation Script, I do see the value of “animation” working appropriately. But perhaps I’m not connecting it all correctly to the png file.
In the template, I kept the boilerplate elements:

Template

Variables

Frames (maximum set to 20)
On(max set to 1)

Animation (image file, it was an SVG but I pointed the bitmap to the png. I have a place to set the value, currently it points to the variable “@Frames”)

Animation Script Template (this houses the script. I exported the parameter “animation” and “on”)

Are you using the Animation Script Example Template? The one with the rotating star?

You should be able to change the bitmap by editing the template and its animation control. Just tried it and it seems to work without changing the script or any other values.

The script I posted was meant to be used with a simple animation control. But if the template works for you just use that.