Stop Users Repeatedly Pressing a Key

Get help using Construct 2

Post » Thu May 30, 2013 8:02 am

Hello!

I am making a small game in Construct 2 and I am unsure how to stop users from repeatedly spamming the mouse button. I want there to be a two-second delay until the user can press the key again.

How would I do this?

Thank you,

Orange
B
8
S
2
G
2
Posts: 49
Reputation: 1,894

Post » Thu May 30, 2013 8:32 am

There are lots of ways of doing this...

Here's one

you can give your object an instance variable lets say cooloff

then add "cooloff <= 0" to your fire trigger meaning cooloff must be 0 or less to work

then when you shoot add a value depending how long you want to cooloff

>on mouse clicked      fire bullet
                      set cooloff to 20    (adjust this number to suit)

then the condition...

>cooloff > 0     subtract 1.0*dt from cooloff

sorry bit rushed, hope that helps...
Pixel perfick2013-05-30 08:35:09
As long as I can move left, right and fire, I'm Happy...
B
42
S
15
G
11
Posts: 655
Reputation: 12,260

Post » Thu May 30, 2013 10:26 am

[QUOTE=Pixel perfick] There are lots of ways of doing this...

Here's one

you can give your object an instance variable lets say cooloff

then add "cooloff <= 0" to your fire trigger meaning cooloff must be 0 or less to work

then when you shoot add a value depending how long you want to cooloff

>on mouse clicked      fire bullet
                      set cooloff to 20    (adjust this number to suit)

then the condition...

>cooloff > 0     subtract 1.0*dt from cooloff

sorry bit rushed, hope that helps...
[/QUOTE]

Hey Pixel!

Thanks for your reply, but I'm a tad confused.... would you have cooloff reduce every tick?

Thank you,

Orange
B
8
S
2
G
2
Posts: 49
Reputation: 1,894

Post » Thu May 30, 2013 10:32 am

You don't need to add every tick, it will only reduce cooloff when it is above zero
As long as I can move left, right and fire, I'm Happy...
B
42
S
15
G
11
Posts: 655
Reputation: 12,260

Post » Thu May 30, 2013 10:35 am

Dt is delta time the internal clock running all the time, just make one condition...

>(your object) compare variable, cooloff > 0....followed by this event

(your object)subtract 1.0* dt from cooloff
As long as I can move left, right and fire, I'm Happy...
B
42
S
15
G
11
Posts: 655
Reputation: 12,260

Post » Thu May 30, 2013 10:44 am

Aah, I've figured it out for myself now. Thank you!
B
8
S
2
G
2
Posts: 49
Reputation: 1,894

Post » Thu May 30, 2013 12:48 pm

@Pixel perfick

hope you don't mind me using that in the near future :P Very useful.. I find it funny how I can't think of something like that originally but as soon as someone says it I'm like: Oh yeah I probably did know that!
B
20
S
7
G
4
Posts: 322
Reputation: 4,521

Post » Thu May 30, 2013 12:55 pm

@sulli Free to use, just give me credit, lol..kidding.
As long as I can move left, right and fire, I'm Happy...
B
42
S
15
G
11
Posts: 655
Reputation: 12,260

Post » Thu May 30, 2013 1:00 pm

@Pixel perfick muhahaha
B
20
S
7
G
4
Posts: 322
Reputation: 4,521


Return to How do I....?

Who is online

Users browsing this forum: ASHKAR, kellehk, R0J0hound, ST314 and 22 guests