IdaJS
    Preparing search index...

    Variable doReduce

    doReduce: (key?: string | number) => (coroutine: unknown) => void

    [COROUTINE COMMAND] Use in the coroutines only; Must be called with yield!

    This function is used to reduce the coroutine position in the truly infinite loops, so that the position does not grow indefinitely. The save game system saves the last position in your coroutine, so if the infinite loop is there, the position will keep growing with time. This functions resets the position counter in the beginning of the infinite loop, still allowing the coroutine to load in the right position after loading a save game.

    A truly infinite loop is a loop that has no exit conditions, or breaks out of it. If your loop has possibility to exit, you usually should not use this function.

    Use yield doReduce(); at the beginning of the truly infinite loop, like while (true), to reset the position counter.

    Type Declaration

      • (key?: string | number): (coroutine: unknown) => void
      • Parameters

        • Optionalkey: string | number

          optional key to identify the coroutine position reducer. Only needed to be provided in the case, there are several infinite loops in one coroutine.

        Returns (coroutine: unknown) => void

    // Coroutine function (must have * after function keyword)
    function* myCoroutineWithInfiniteLoop() {

    // Example of some coroutine operations before the infinite loop:

    yield doMove(ida.Move.TM_SAMPLE, 16); // Play audio sample 16

    // Starting a truly infinite loop
    while (true) {
    // Reduce position counter to avoid it growing indefinitely
    // (will reduce the position to 1 in this case,
    // as this is the position of the first doReduce call in this coroutine).
    yield doReduce();

    // Example of some coroutine operations in the loop:

    // Play animation 12
    yield doMove(ida.Move.TM_ANIM, 12);

    // Wait for 2 seconds
    yield doMove(ida.Move.TM_WAIT_NB_SECOND, 2);
    }
    }