Cannot get setInterval to work

I’m attempting to run some code in a loop using setInterval, but without any success.
My code:

export function hero_viewportEnter(event) {
 let rollOptions = {
 'duration': 1200,
 'direction': 'left',
 'delay': 500
 };

    setInterval(() => {
    setTimeout(function () {
 let value = "Information.";
        $w("#trusted").text = value;

        $w("#trusted").show('roll', rollOptions);
        $w("#trusted").hide();
 }, 500);

    setTimeout(function () {
 let value1 = "Team.";
        $w("#trusted").text = value1;

        $w("#trusted").show('roll', rollOptions);
        $w("#trusted").hide();
 }, 2000);

    setTimeout(function () {
 let value2 = "Advice.";
        $w("#trusted").text = value2;

        $w("#trusted").show('roll', rollOptions);
        $w("#trusted").hide();
 }, 3700);
 }, 5000);
}

Would be grateful if someone could point me in the right direction.

This setInterval() method should be inside the $w.onReady() method to start as soon as the page is ready, or inside the _viewportEnter() method to start on viewport render, otherwise, it is not going to work.

The code syntactically seems correct, as everything is under the correct brackets, but I think the issue is with the “times” which you have set.

The first set timeout has a timer of 500 milliseconds, which itself has a function of show, which has a delay of 500ms and a duration of 1200ms. Because of this additional time, my speculation is that there are multiple shows() , hides() and setTimeout() being called at the same time, which might be causing the error.

Try changing the time limits, and have enough time in between for functions to test it out.

I hope this helps :slight_smile:

Thank you!

Yes, it helped a lot. Thank you.