How do I use the same Key Button for doing two things

Get help using Construct 2

Post » Fri Jul 08, 2016 2:30 am

Hi guys, im trying to use the same Keyboard Button to do tow different things. If i mantain pressed the x button, timescale should go to 0.5, but if i just press the x button but not held it down i should do a Dash. I know how to do te two things with different buttons, but i need to use the same button if pressed but not held down, and if held down.

X pressed but not held down ---> Dash
X pressed and held down ----> Set Timescale to 0.5 as long as the X button is held down (Dont do dash if held down)
B
28
S
4
G
1
Posts: 23
Reputation: 2,766

Post » Fri Jul 08, 2016 7:54 am

Hmm, this might not be the best solution but off the top of my head maybe add a variable as a kind of timer and use it to gauge how long the key is pressed. Something like,

X is pressed -> Add 1 to Variable
X is released + Variable<20 --> Dash (i.e. if you tap the key without letting Variable build up to 20, you dash)
Variable>20 --> Slow time (so if you hold X down for a bit, timescale changes)
X not pressed and Variable>0 --> Set Variable to 0 (to reset)

And then adjust the value at which time slows to strike the balance you need.
B
51
S
24
G
18
Posts: 293
Reputation: 13,061

Post » Fri Jul 08, 2016 9:12 am

The solution provided sounds correct and it is called a buffering input.

Although you should actually reset your variable to 0 in the "On release" no matter what, using a blank event for example.

Key is pressed => Add dt to variable (Delta Time)

Key on release
... Variable < 0.5 => Do dash
... Variable => 0.5 => Do Slow time
... (blank) => Reset Variable

This way your variable will only build up when you are pressing the key.
And the time there are akin to pressing the key for half a second. Using dt, you are getting an exact value of 1 added each second the key is down in a consistent manner over all computers.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
289
S
112
G
94
Posts: 7,333
Reputation: 69,293

Post » Fri Jul 08, 2016 5:35 pm

Thanks to both, i managed to make it work C:!
B
28
S
4
G
1
Posts: 23
Reputation: 2,766

Post » Sun Aug 28, 2016 10:23 am

Good answer, stopped my player using his pickaxe as soon as i pushed the button.
B
8
S
1
Posts: 51
Reputation: 577


Return to How do I....?

Who is online

Users browsing this forum: jorgmaquoi, sean080, Yahoo [Bot] and 25 guests