Delay to creating objects

Hi everyone. I need help at someting. I need creating same object with some delay. Like 0.3 sec. I used “Value of a timer” and “reset timer” and it works. But now i have an another problem.

In the game when you press “u” button player shot a ball. Like a said i can give delay with “Value of a timer” and “reset timer” but now when you keep press the button, the object keep creating also. What i want is one object creating for one pressing.

I tried some ways in my knowledge but it didn’t help. It ending with lock the creating object if you press fast.

So i need your help :slight_smile:

Btw sorry for my English.

It’s because you have only one timer, but you need a timer for each shot actually. I would do it:

  1. When you press the shoot button, create an empty object, an invisible sprite or something, don’t worry about the position, I will call it Placeholder (the position doesn’t matter, so maybe Timeholder would be a better name?)
  2. Just after creating the Placeholder, create an object variable for the Placeholder called Lifetime = 0.3
  3. Always (every frame), do -TimeDelta() to the variable Lifetime of each Placeholder. Here is the magic, the variable Lifetime is like a little timer that works for each shot because it’s an object variable, the timers are global
  4. Finally, if the variable Lifetime of a Placeholder is <= 0, delete the Placeholder and create the Bullet in the right location (the gun or whatever)

Let me know if you need an example or something :slight_smile:

Can you make an example for -TimeDelta() ?

I’m new here, so I don’t know much nya, but to avoid multiple instances of the same object I would do this:

  • I just create a simple variable, like, “ballexists” with a starting value of 0. “0” means there is no ball in the screen nya.

-In the instance where you press “u” and a ball is created, where it says something like “When the key (u) is pressed”, nya, add an effect that changes the value of that variable, “ballexists”, to “1”.

-Then add to the same ball creating instance, where it says “When the key (u) is pressed”, a condition that says that the variable “ballexists” must be 0.

-Finally, in the event when the ball is deleted, add an effect that changes the value of the variable back to 0.

I think that could solve the multiball problem nya.

Here is what I mean: (4.09 KB)
In the example there are two scenes, the first one is a debug scene where you can see the placeholders and their timer, the second scene is a “release” one, debug objects and events have been removed :slight_smile:

Are you using the “Trigger once” condition? Alternatively, you could create the ball when the U button is released, rather than when it is pressed. Either of those should stop lots of unwanted balls being created. If you want to hold down the U button and create lots of balls, but with a delay between each one, then you’ll need something like Lizard’s suggestion.

Hi everybody. First of all thank you so much your help and i’m sorry didn’t answer before.

So I fixed my problem. I tried your ways 1 by 1 but it didn’t help but it because probably I didn’t do it right.
But here is the funny part. I took some stuff your help and combine together and it works now :slight_smile:
I know %90 why it works but not sure what is going on that %10 part. But right now I’m on “God dammit it is working, don’t touch it” mod.

Anyway once again thank you so much your help.

1 Like