Python wait duration/seconds

I’m trying to get an FPS scene working, but I need to have python wait for a set duration… I found the ‘Delay’ sensor, but I have no idea how to integrate that, or use some other way…
I also don’t get any wiser from this page…

Any way to make python wait for logic tics, frames(probably, not the best way I’m guessing), milliseconds, seconds?

Is there any reason you cant use a timer property on an object?

Could you get me started on that? I’ve been mildly successful in getting scripts running, when I know what commands I need to use… And for this, I don’t. Isn’t there just something like ‘sleep (milliseconds)’ or something I can use in my code?

  1. set a int property named count to the object ( set it to 1)
    set a Timer property named Timer to the object ( set it to 0)
    set a int property named event to the object ( set it to 1 or 0)
    set a float property named wait to the object (set it to 0)

  2. link the script to an always sensor ( with pulse mode)


cont = GameLogic.getCurrentController()
own = cont.owner
def wait(x):
    own.wait = x
    own.count += 1
    own.event = 0
    own.Timer = 0
if own.event == 0:
    if own.Timer >= own.wait:
        own.event = own.count
if own.event == 1:
    print "event number 1"
    wait(10)
if own.event == 2:
    print "event number 2"
    wait(2)
if own.event == 3:
    print "event number 3"
    wait(15)
if own.event == 4:
    print "event number 4"
    wait(4)
##etc...

  1. ???
  2. Profit!

Thank you, I’ll give it a go.
Hopefully I won’t drain my clips when I reload and fire…

updated the script on my previous post to have better control on the “wait” function.

so is that script basically just like the delay sensor? ive got the same problem and i only know the “hello world” script. thats as advanced as i am…jk… but seriously could i just use the delay sensor?

my script doesnt act exactly like the delay sensor… the delay sensor is used to delay … the START of the script.
as my script is used to delay INSIDE scripts.

ohhh ok. ya im not too good with scripting… at all…

this doesn’t work. when i run this script a get a frameout warning and nothing else happens.

This, however, does work:

  1. add Timer property “Time”
  2. add Float property “starttime”
  3. add Float property “wait”
  4. add always sensor
  5. add python controller with following script:

cont = GameLogic.getCurrentController()
own = cont.getOwner()

if own.Time>=(own.starttime+own.wait):
print “wait complete” #This is where the code for your event should go
own.starttime=own.Time

The own.wait property can be set in blender or by another script, depending on what you are trying to do.

The delay sensor can be a bit tricky, and it’s best used alongside states. It’s somewhat similar to the always sensor with the F setting changed, but offers more flexibility.

The “Delay” variable is the duration (in logic tics) before the sensor sends out a true pulse. By default, there are 60 tics/second, so if you set this to 60 it should fire a pulse after 1 second has passed. For example, if you set delay to 120 and attach it to a property actuator, that property actuator will be activated 2 seconds after the game starts.

Normally, a “false” pulse is sent once a sensor is no longer active. False pulses deactivate certain actuators (such as the motion actuator). The “Dur” value sets the delay between the true pulse and the false pulse. If you wanted to have an object start moving forward after 1 second, and only move forward for another second, you can set Delay to 60 and Dur to 60 and attach it to your motion actuator. Note that when Dur = 0, no false pulse is sent.

Finally, the “rep” makes the delay sensor loop. A delay sensor with Rep enabled and a delay of 60 will send a true pulse once a second. If both delay and dur are 60, it will send one pulse after 1 second, then will repeat every 2 seconds (dur+delay).

When not attached to anything, delay sensors don’t do anything. If a state where the delay sensor suddenly is attached to something is activated, the delay sensor will start up from scratch. If you wanted to sort of pause an object’s activities for 2 seconds, you could change to a state with a simple delay sensor set to a delay of 120 attached to a state actuator that returns to the old state.

I hope that explains the delay sensor a bit more!

-Sam