Object timer

Can be very useful if we could use timers individually for every object.

The problem with the present timer is that it more like global.
For example, let say if I press a key, I want on object to be created but after 1 sec I want every object to be destroyed individually.
If I set a timer “for each object” to be destroyed after 1 sec and reset the timer, it works in terms of the objects is destroyed individually but one after an other. The objects always wait for the previous object to be destroyed. So if I create 10 object, the 10th object going to wait 10 sec to be destroyed instead of 1.

If you would like to see, I have the example here:
docs.google.com/file/d/0B1sXiYO … sp=sharing

So it would be great if we can have a “Timer” category under “All objects” and we can create and use an object timer the same way just like an object variable.

Object’s variable “life” turned classic in my tests :smiley: , with a global timer “set_lifes” you add a little of time to each oject’s “life”, when the variable become > 1, destroy the owner object. In this way, each object’s life is independent, because their variables are independent too.

[code]Timer “set_lifes” >= 0.1:
…Do “+” “0.1” to variable “life” of “oject”
…Reset timer “set_lifes”

Variable “life” of “object” >= 1:
…Destroy “object”[/code]

Hi Lizard. thanks for your help, but I’m not sure If I understand what you mean (maybe I’m too tired).

The problem is that, even if I use variables and I use timer on the object variables instead of the object itself, doesn’t make any different, because the timer is basically a global time. Even if I want to effect the variables which is local, the timer is global and moves one by one, one after another and the last object\variable has to wait longer to be affected by the timer.
What I need in this situation is a local timer to use a local time for every object or even variable, individually, because if a new object\variable is created before the previous is finished, need to start a new timer at the same time. But I found it not possible in this situation because I’m using the same timer on multiple objects in different times which makes more difficult.
So even If I use object variables, the timer is global which makes the timer move one by one and makes no different.

I’ll give a try to variables tomorrow, but at the moment the only solution I can think of is to use local (object) timer for every object or variable individually, but GD don’t have this feature.

A timer is just a variable which is incremented each frame by the time elapsed in the last frame. So you can emulate a timer by doing:

Conditions: None Actions: Do +TimeDelta() to the value of variable MyTimer

Or if you want a specific timers for each object:

Conditions: None Actions: Do +TimeDelta() to the value of variable ObjectTimer of object MyObject

You can then reset the timer of an object:

Conditions: MyObject is colliding with Obstacle Actions: Do =0 to the value of variable ObjectTimer of object MyObject

or compare the time elpased:

Conditions: Variable ObjectTimer of MyObject is >5 Actions: Do something for objects having their timer > 5 seconds.

Remember that variables are specific to each instances of each object, so there is nothing you cannot do with variables compared to timers.

Thanks 4ian, the “timer emulator” works :slight_smile: