0

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?

Michael Teller
  • 71
  • 1
  • 2
  • 7
  • Are you looking for `deterministic random alrorithm` or `shuffle algorithm` or `return 1..N algorithm`? what exactly – Dimava Nov 12 '22 at 21:54

1 Answers1

1
// 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

Dimava
  • 7,654
  • 1
  • 9
  • 24