Disabling keys with global variables bug

Get help using Construct 2

Post » Fri Jan 04, 2013 1:46 pm

https://www.dropbox.com/s/thtzc3nb1r21q8r/Spacewarripoff.capx

Hi Guys,

I've been trying to set the spaceship controls so that it is only possible to fire after an interval so that spamming doesn't slow down/break the game.

Using a global variable as a boolean to detect if the button has been pressed recently only seems to work occasionally which means that after the first interval has been reset, the game allows the player to spam fire again.

You will find the events at the top of the controls group.

Thanks!
B
3
Posts: 9
Reputation: 343

Post » Fri Jan 04, 2013 2:32 pm

How I've always gotten this to work is using a global something like this:

On Key Pressed
Global Variable 'Cooldown' set 'false'
--------
Set value 'Cooldown' to 'true'
(Fire stuff here)
Wait 0.5 seconds
Set value 'Cooldown' to 'false'

I'm away from my computer so I can't check C2 for exact verbiage, but that should work. A few things to note, if you use touch input or 'if key is down' add 'trigger once while true' to your conditions for something like this or you'll get strange problems sometimes for events such as this. Let me know if this way works for you.
B
90
S
32
G
14
Posts: 935
Reputation: 14,540

Post » Fri Jan 04, 2013 2:36 pm

Custom timers always worked for me..

https://dl.dropbox.com/u/666574/bootsie%20-%20spacewarripoff.capx
B
15
S
5
G
7
Posts: 877
Reputation: 5,650

Post » Fri Jan 04, 2013 3:28 pm

Thanks Procrastinator, that works well now. The timer looks like a far more robust system.

Thanks again guys, nice one.
B
3
Posts: 9
Reputation: 343

Post » Fri Jan 04, 2013 4:05 pm

The way you had it you'd need a trigger once condition in there:

System: P2Fired = 1
System: Trigger once
   -> System: Wait 0.7 seconds
   -> System: Set P2Fired to 0

otherwise that event is running every tick for 0.7 seconds while P2Fired = 1. Then after 0.7 seconds all the delayed actions will run, setting P2Fired back to 0 for the next 0.7 seconds.
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,000


Return to How do I....?

Who is online

Users browsing this forum: Timedoor Indones and 25 guests