Countdown timer start on Record

Hi there!

Have a timer countdown with this script

//@input Asset.Texture[] timerTextures
//@input Component.SpriteVisual[] columns
//@input int time {"label":"Time", "min":0, "max":9999, "step":1}
var updateTime = script.createEvent("DelayedCallbackEvent");

// change time to however many seconds you want the timer to last
var time = script.time
var minutes = 0
var seconds = 0
var secondsOnes = 0

updateTime.bind(function(eventData)
{  

    seconds = time - (minutes * 60)
     print(time.toString());
     print(seconds.toString());
    
    if(seconds > 9){
            secondsOnes = Number(String(seconds).charAt(1));
    } else {
            secondsOnes = Number(String(seconds).charAt(0));
    }
    
    updateTimerSprites();
    time--;
    if(time >= 0){
    updateTime.reset(1);
    }
});

updateTime.reset(1);

function updateTimerSprites(){
    script.columns[0].mainPass.baseTex = script.timerTextures[secondsOnes];
}

How can I start this countdown when user start Recording Snap
I know about SnapRecordStartEvent class but I’m not sure how to apply it

It works just like other events. You can set it up to reset the callback like this:

script.createEvent("SnapRecordStartEvent").bind(function() { updateTime.reset(1) })

1 Like

Got it! Thank you!

Solved

//@input Asset.Texture[] timerTextures
//@input Component.SpriteVisual[] columns
//@input int time {"label":"Time", "min":0, "max":9999, "step":1}
var updateTime = script.createEvent("DelayedCallbackEvent");

// change time to however many seconds you want the timer to last
var time = script.time
var minutes = 0
var seconds = 0
var secondsOnes = 0

updateTime.bind(function(eventData)
{  

    seconds = time - (minutes * 60)
     print(time.toString());
     print(seconds.toString());
    
    if(seconds > 9){
            secondsOnes = Number(String(seconds).charAt(1));
    } else {
            secondsOnes = Number(String(seconds).charAt(0));
    }
    
    updateTimerSprites();
    time--;
    if(time >= 0){
    updateTime.reset(1);
    }
});

script.createEvent("SnapRecordStartEvent").bind(function() { updateTime.reset(1) })

function updateTimerSprites(){
    script.columns[0].mainPass.baseTex = script.timerTextures[secondsOnes];
}

Nice! Yes this is exactly what I was going to say :slight_smile:

2 Likes

Do you know how can i set the loop time, I need my timer loop every 5 second

//@input Asset.Texture[] timerTextures
//@input Component.SpriteVisual[] columns
//@input int time {"label":"Time", "min":0, "max":9999, "step":1}
//@input int delay
var updateTime = script.createEvent("DelayedCallbackEvent");

// change time to however many seconds you want the timer to last
var time = script.time
var minutes = 0
var seconds = 0
var secondsOnes = 0
var delay = script.delay
var loops = 4;
var offset = 0.0;

updateTime.bind(function(eventData)
{  

    seconds = time - (minutes * 60)
     print(time.toString());
     print(seconds.toString());
    
    if(seconds > 9){
            secondsOnes = Number(String(seconds).charAt(1));
    } else {
            secondsOnes = Number(String(seconds).charAt(0));
    }
    
    updateTimerSprites();
    time--;
    if(time >= 0){
    updateTime.reset(1);
    }
});

script.createEvent("SnapRecordStartEvent").bind(function() { updateTime.reset(delay) })

function updateTimerSprites(){
    script.columns[0].mainPass.baseTex = script.timerTextures[secondsOnes];
    //set loop    
    var provider = script.columns[0].mainPass.baseTex.control;
    provider.play(loops, offset);
}


It seems like your provider is not the right class because it’s missing the play method. You could try using that asset in the script input params directly and see if that works

1 Like

Ahhh, i decide just duplicate the timer script and set different delay :smiley: