wait 5 seconds in DAT script

Hi all,
I just want to ‘wait’ 5 seconds in a script, but
time.sleep(5)
actually freezes TouchDesigner for 5 seconds.
What’s the proper way to do this?
I want to execute a few things in a script but want to space them out specifically over the course of several seconds.
Cheers!

Hi, had similar problem while ago. Had to execute script only a few times a minute.
Simple way around it is to use CHOP Execute, and trigger it by using beat with 5 second period.

Wow, I suddenly don’t feel like an idiot because that’s exactly what I came up with.
One execute to turn off the reset on the Beat CHOP and Counter CHOP it runs into, use % in the script so it triggers every 5 seconds, then at a certain value turns n the reset on the beat and counter chop.
thanks dblonka! but still, no python workaround? starts to get cluttered to have to add chops in for stuff like this, but gotta do what you gotta do

Not so elegant way will be using something like this in Execute DAT, global variable ‘done’ is for ensuring one time execution every 5 seconds.

import time
done = False

def frameStart(frame):
	global done
	if (int(time.time())%5 == 0) & (done == False):
	
#		Put your script here	
#		print(int(time.time()))
		
		done = True
	elif (int(time.time())%5 != 0) & (done == True):
		done = False

	return

Theres 3 ways to do this that we usually use. The first is using the run class as such:

script = "print('im running now')" run(script, delayFrames = 5*me.time.rate)

Which allows you to run some delayed Python without having to make another Text DAT and put delayFrames on it, but depending on the size of the script you need launched that’s an option as well. So for example if

print('im running now')

Was in a Text DAT named “runMe”, then from your controller script you’d put:

op('runMe').run(delayFrames=5*me.time.rate)

The third option is basically just a mix of the two, so what you’d do is make a module you could run, and you’d use the first method but since you have the function written elsewhere it still remains concise. Let me know if you want an example of that and I’ll make a project file.

1 Like

One small note:
instead of
delayFrames = 5 * me.time.rate
You can simply use:
delayMilliSeconds = 5000

Also, we have a new Timer CHOP that is a general timing tool which might help.
derivative.ca/wiki088/index. … Timer_CHOP