Timer Problems... NameError: global name 'Timer' is not defined

Hello everybody!

i am a new Python / Blender user from Spain and i am building my first game prototipe.

I Post this thread because i am getting an error using a timer and i don’t know how to solve… i hope somebody here can help me…

I need to control a time interval and i am trying to use a timer… this is my code:

t = Timer(2.0, controlJet)

later i start the timer like this:


controlJet is the function i want to call when the 2 seconds has passed… but when i try to make it run i get this error:

NameError: global name ‘Timer’ is not defined

i don’t know how to fix it, i imagine everything is because i don’t import its class, but i don’t know wich one is it, so if somebody could help me please, it would be nice…

Thanks a lot!

The module is called “time” see python docs.

Be aware the BGE is not thread safe. Be careful when using threads.

Better use a timer property and evaluate the property with a property sensor.


Name: time; type: Timer; init: 2.0 (= seconds)
property sensor (no Pulses; mode: interval; prop: time; min: 0; max: 9999)
—> whatever you want to trigger

Thank you! But i don’t know exactly how to do that… :frowning:

When i import “time” it doesn’t work… stay the same error message “global name ‘Timer’ is not defined”

and because my code is into a python controler, i don’t know exactly how to evaluate that timer property with the property sensor…

I need to check when the player shoot, and then wait for 2 seconds to can shoot again… any idea?

Thank you very much!

Timer is a thread. As said do not use it.

better use a timer property as described in the above example (post #2).
The Property Sensor does the evaluation for you. Just check the sensor to be positive.

It’s actually quite easy to do something like this in the BGE.
The easiest way is to use a timer property.
That starts at 0 when the game starts, and continues to count up in quite some accuracy until you end the game, or reset it to 0.
You can use a timer property, and a property sensor.
Set the property sensor to measure an interval from 2 to 2.1
Then, connect it to your module.