Cooldown for Cook Time

Is there an easy way to create a cooldown time for a scriptTOP (or any op for that matter) so that it doesn’t run the script on every cook? I’ve got data coming in that doesn’t change every cook, but I would like to change other op parameters when that data actually does change. Can anybody recommend a good method to do this? Or possibly a way to avoid cooking this on every frame?

Several ways.

The most important one: nodes only cook when something is asking it for data. So for instance if you place a Switch TOP after the Script TOP, the Script TOP will not cook when the Switch is set to a different input than the Script TOP. So you can use this to circumvent the Script TOP, and change the Switch TOP’s index when you need the Script TOP to cook.

Using this principle is the recommended way, as it is builtin into TD’s core, and heavily optimized. Read this: What causes cooking

Other less optimized ways:

You can lock it the Script TOP. Then you can call op(“script1”).cook(force=true) from anywhere in TD when you want to cook it for a single frame.

Or another way, let the onCook() callback of the Script TOP contain only a single call to a method in an Extension you create, and let that method decide to either execute code or to return immediately.

1 Like

Ahh I was waaay overthinking it. Thank you!