1

I have a loop animation that has a random duration (generated by Random patch):

enter image description here

When the pulse is received, loop animation (and several other animations/random generators) is triggered, creating new random values. When the effect starts this works fine. Though I want to trigger a new random value generation upon animation completion (which also would trigger a new duration for my next animation loop, which I want to be random too):

enter image description here

However, because of creating a loop (pulse -> animation -> looped output -> back to same pulse) I get the "Two or more patches have been connected multiple times, creating a loop" error:

enter image description here enter image description here

I understand the cause of the error: creating a loop is not supported as it can create circular dependencies, though logically what I'm doing should be possible. I'm trying to change the duration of the animation upon completion. How can I achieve this?

Can Poyrazoğlu
  • 33,241
  • 48
  • 191
  • 389

1 Answers1

3

I've solved it by instead of creating a loop by using the Looped output of the loop animation patch, I've created a script that both generates the reset pulse signal and a random number for duration, creating a one way graph (both random duration scalar signal AND reset pulse signal going into the animation and reset signal also going into any other random triggers in my patches) instead of feeding the output of the animation.

Here is my script for reference:

import Reactive from 'Reactive'
import Patches from 'Patches';
import Time from 'Time'


var minDuration:ScalarSignal;
var maxDuration:ScalarSignal;

async function regenerate(){
    var currentMin:number = minDuration.pinLastValue();
    var currentMax:number = maxDuration.pinLastValue();
    var random = currentMin + (Math.random() * (currentMax - currentMin));
    await Patches.inputs.set('duration', random);
    await Patches.inputs.setPulse('resetAnimation', Reactive.once());
    Time.setTimeout(async () => {
        await regenerate();
    }, random * 1000);
}

(async function () {

    minDuration = (await Patches.outputs.get('minimumDuration')) as ScalarSignal;
    maxDuration = (await Patches.outputs.get('maximumDuration')) as ScalarSignal;
    await regenerate();
})();
Can Poyrazoğlu
  • 33,241
  • 48
  • 191
  • 389