Sleep in python

Hello,

I am making a traffic light in blender game engine. I made a simple script that currently just prints green waits 10 seconds prints yellow then red and over again. I am using the module time and using time.sleep(10). but everytime i use this it prints and waits as usual to the console but it crashes blender. when i don’t activate the script it is fine. is there any alternative to time.sleep? or anyway to stop blender from crashing? if need the blend just ask. Thx

-Matthew

yeah, sleep() pauses everything,

what you want is a different trigger event than

always(every pulse)---------python

you want

always(every 10 frames)------------python

No, what he wants is each 10 seconds not 10 frames. That would be 600 frames on a 60FPS game. If the game ever drops from that frequency the always sennsor will start taking more. At this point is just better to implement a Timer in Python.

Note: I said FPS but actually that’s frecuency of logic ticks, wich usually is more consistent but it still can drop from 60Hz in some cases.

Thanks for telling me about time.sleep but I want to put the delay in a python script and not in logic bricks. Is there any way to do that?

you can have a small callback, use a counter, and call your python script whenever the number is divisible by 10?

avoiding logic bricks is insane though, they are your link to events.

like

if timer!=0-----------------(python (do stuff and Timer-=1))

(run until timer is empty)

and you can have another script

if time==0------------------(think about what to do)

etc.

Use time.time() to get the current time. Then on the main loop you check for events. If you want an example with only Python I’ll send it later.

thanks i got it working! :smiley: