A simple script for a delay controller?

I’M looking for a simple python script I can cut and paste off this forum into the python controller that will allow me to delay the pulse out for a chosen period of time.
Thats all I’m asking.
I have searched the forums for an hour and I’ve seen lots of help from people answering the same question saying there lots of different ways to do it with state change and the delay senor, time variables, ETC. But that adds lots of extra bricks to accomplish something that should be so simple. There should just be a Delay Sensor anyway. But since there isn’t I’m just looking for a simple python script I can add to the controller to do the delay with just one controller brick.
Thanks for the help.

How about that?

You should be a bit more specific what you want to achieve. Your request is very unspecified. In an event system as it is used with the BGE - the typical question is: WHAT should happen WHEN?

Both can be complicated (the what and the when). To give you a sufficient advice how to describe the desired behavior either in Logic Bricks or in Python or as a mix we need to know more details.

You are talking about a delay. A delay typically is has a start and a duration. So the WHEN is when the delay should start [So you need a sensor to measure that]. The according WHAT is … the delay starts. So you need an action that starts the delay [You can do that with an state change]. This means the delay is an event triggered operation by itself.

The following -not described- action [another WHAT] can be triggered with the end of the delay [another WHEN].

So you see two operations -> two WHEN and two WHAT. Even with Python you need to describe both.

Operation A:



Operation B:

Btw. This is a very efficient method, as any logic brick runs when it is needed only.

Thanks again for the reply.
I meant to say there should be a delay CONTROLLER (not sensor) to achieve a delay between the time a sensor fires and the time the actuator goes off. The set up you show above works for sure but its more bricks to do the delay when you have to change states. You would proably also want to change back to the orginal state after the delay. Then if you have multiple delays to do you would have to change states for all off them then change back to the orginal stae.
Just seems more straight forward to have a delay controller where you could just input the delay time before it fires the actuator off. Anyway I was hoping there might be a script out there i could plug in to the controller script input that would do this.

just put your code in a object then do

trigger--------------python

import bge
scene=bge.getCurrentScene()
added=scene.addObject(‘object_with_code’,own,0)
added[‘delay’]=???

then in the object

always----------and-------------add 1 to delay

if time=delay------python

A controller can’t delay anything. If triggered it runs at the current frame. All output is influences the current frame (not the future). As I wrote above you need two events to measure: the delay start and the delay end.

With Python you might evaluate both events in one logic brick. It means nothing more then moving both logic bricks into Python code. But It also means you need to unnecessary trigger the controller when it is not needed. A controller is a very inefficient sensor.

If you need several delays you can use several states, or properties or whatever method you use to measure the delay.

If there are really much delays you might think about a scheduler object that sends out messages when a delay ends. But you would need some Python knowledge to build one.