Construct 2/3: Continuous Loop Function?

242 views Asked by At

Using Construct 3 to build a game.

I want to change this function in the code below (which just randomly assigns a frame count in an array) to something that isn't random, but instead loops in order from indexes 0 to 10 and then back to 0 and then to 10 in order again and loop like that continuously.

 random(1,Self.AnimationFrameCount)

Is there a random() equivalent for non-random?

1

There are 1 answers

0
Dimava On
// generator function - yields multiple times, maybe forever
function* oneToTenAndBack(N: number): Generator<number> {
    while(true) {
        for (let i = 0; i < N; i++) yield i;
        for (let j = N; j > 0; j--) yield j;
    }
}

let k = 0;
for (let num of oneToTenAndBack(4)) {
    console.log(num) // 0 1 2 3 4 3 2 1 0 1 2
    if (++k>10) break;
}
let gen = oneToTenAndBack(3);
for (let k = 0; k < 10; k++)
    console.log(gen.next()) // {value: number, done: false}

Playground Link