Is there some way of having a time delay within a script somehow? What I mean is, when the user clicks something, how do I call a function like a couple of seconds later? And have control over the time it takes to call the function.
I tried
import time
time.sleep(1)
but this stops blender to stop, not just a delay within the script. I’m sure there is a relatively easy way to do this, just cant find anything on it.
Or, if you’re doing this inside of a function and don’t want to wait until the timer’s up to execute the script, use a variable and increment it every frame.
obj = cont.owner
if not 'init' in obj:
obj['init'] = 1
obj['timer'] = 0.0
obj['timer'] += 1.0 / logic.getLogicTicRate()
if obj['timer'] > 10: # 10 seconds
#Do something
It sets up the delay between two consecutive pulses without a sensor’s state change. As this delay can be skipped on state change it is not really a good option for time measure.
Marco is right: the always sensor does not change state. So you could use it. Be aware the sensor will not stop to send pulses ;).