Why doesn't this work?

Hi, trying to make a simple parallax tool.
when I use app.command.MoveMask after adding the frame, it works fine.

However if I add another loop and I set the active frame, it doesn’t work properly.

        local args = dlg.data
        local sprite = app.sprite
        -- sprite size in correspondent axis (x for now) / n_frames * speed
        local final_speed = sprite.width / args.frames * args.speed

        sprite.selection:selectAll()
        local n_frames = #sprite.frames
        local req_frames = math.max(0, args.frames - n_frames)
        for i = 1, req_frames do
            sprite:newFrame()
            app.command.MoveMask {
                target="content",
                wrap=true,
                direction="left",
                units='pixel',
                quantity=final_speed
              }
        end

        sprite.selection:deselect()
        app.refresh()
        -- DOESNT WORK
        local args = dlg.data
        local sprite = app.sprite
        -- sprite size in correspondent axis (x for now) / n_frames * speed
        local final_speed = sprite.width / args.frames * args.speed

        sprite.selection:selectAll()
        local n_frames = #sprite.frames
        local req_frames = math.max(0, args.frames - n_frames)
        for i = 1, req_frames do
            sprite:newFrame()
        end

        for i = 1, #sprite.frames do
            app.activeFrame = i
            app.command.MoveMask {
                target="content",
                wrap=true,
                direction="left",
                units='pixel',
                quantity=final_speed
              }
        end

        sprite.selection:deselect()
        app.refresh()

Thanks

hi, what happens if you replace app.activeFrame = i with app.frame = app.sprite.frames[i]?
i saw sprite.frame[i] in examples here: https://github.com/aseprite/api/blob/main/api/app.md#appframe and here: https://github.com/aseprite/api/blob/main/api/sprite.md#spriteframes

yeah sadly that doesn’t seem to work