0 Favourites

Cooldown / Timer

This forum is currently in read-only mode.
  • Complete programming noob here. This is actually a bit of a logic problem, and I'm sure I'm overlooking something really simple, but:

    I've got a special power for my spaceship that can be fired once every 10 seconds (or longer, we'll see).

    Condition: On key X pressed

    For Loop 0 - 100 (making plenty of bullets)

    Set each bullet to random angles

    It works perfectly, and inflicts the carnage I like. But like I said, for whatever reason I can't get a cooldown working. I know I have to reinitialize the timer object to 10,000ms at the end of the bullet explosion, and wrap the whole thing in a while loop to evaluate whether times up or not...but getting that work is another thing entirely

    On a more positive note, having never done any scripting before I've already created something fun in a few hours - so thanks for such a great program!

    -A

  • Hi. There are several ways to do that. I made an example of a simple one, here:

    http://dl.dropbox.com/u/5868916/cooldown.cap

    The text object is just there for a visual cue as to what is going on. For example, try removing the Trigger Once and see what it does. I use this method quite often to ensure that I know what is being executed, when.

  • Perfect. Got it working, Thanks so much for the help!

    -A

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • One last question in regards to delays / cooldowns:

    I'm trying to add a delay in a for loop, but what looks logical, only spawns 1 object (instead of 10 over 10 seconds)

    For "AINum" from 0 to global('MaxAI')

    spawn 1 AI

    Wait 1 second

    resume

    Either they all show up at the same time, or just the one. I'm sure it's a simple order thing, but so far I've yet to figure it out.

    -A

  • For loops all occur in the same frame.

    What you probably want is to set up a counter variable and initialize it to the number of objects you intend to spawn (10, in your case). Then, just do a check each frame to see if a second has passed, and also if the counter is above zero. If so, decrement the counter and spawn an object.

    This has the added benefit of allowing you to seamlessly start spawning more objects simply by setting the counter to a higher number again.

  • How about something like this:

    + System: Is global variable 'EnemyBatch' Greater than 0

    + System: Every 1000 milliseconds

    -> System: Create object Enemy on layer 1 at (random(DisplayWidth), random(DisplayHeight))

    -> System: Subtract 1 from global variable 'EnemyBatch'

    Works like this: as long as EnemyBatch is more than 0, it will repeat once every second. Spawn an enemy, decrement EnemyBatch. Tested and working nicely.

  • How about something like this:

    + System: Is global variable 'EnemyBatch' Greater than 0

    + System: Every 1000 milliseconds

    -> System: Create object Enemy on layer 1 at (random(DisplayWidth), random(DisplayHeight))

    -> System: Subtract 1 from global variable 'EnemyBatch'

    Works like this: as long as EnemyBatch is more than 0, it will repeat once every second. Spawn an enemy, decrement EnemyBatch. Tested and working nicely.

    That's pretty much exactly what I said, isn't it?

    Seriously though, that's more intuitive than the way I put it. I really should just stick to writing pseudocode instead of over-explaining

  • Awesome, thanks again for the help guys. I appreciate both explanations

    -A

  • I used a similar cooldown variable in a game of mine.

    It's one of the first things I actually got working properly in Construct.

    (I use 10 ms and multiples of 10 because of that warning that the milisecond rate isn't accurate

    so cool_down = 100 means 1,000 ms.)

    Trigger (eg Left mouse is down):

    [subevent]

    spaceship.value('cool_down') equals 0: fire BFG (or a loop subevent to fire 100)

    Set spaceship.value('cool_down') to 10

    Every 10 miliseconds

    spaceship.value('cool_down') greater than 0: Subtract 1 from spaceship.value('cool_down')

    If you hold the mouse button (or whichever condition you set), then each tick it checks the cool_down. If it is not zero, then nothing happens.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
0 Favourites
[Behavior] Cooldown
41 28,652
mistia's avatar
mistia
Unread hot topic
27 4,205
Bl4ckSh33p's avatar
Bl4ckSh33p
Unread hot topic
0 Favourites
[Behavior] Timer
31 16,716
rexrainbow's avatar
rexrainbow