How do I Key presses using events between layouts?

Get help using Construct 2

Post » Wed Aug 19, 2015 12:49 pm

I'm doing this:

X is down = Set variable Action1 to 1

To made a key press i do:

Action1 = 1
Trigger Once -> Do an action

And works correct. The problem is when the action is for skip a layout from another that when i press X to Skip instead of skip 1 layout skip a lots of them, so for that the "Trigger Once" not works because do one for layout.

How i solve that?
B
23
S
10
G
3
Posts: 545
Reputation: 4,442

Post » Wed Aug 19, 2015 2:56 pm

Maybe try having the 'press X' action group disabled on the next layout and wait for 1.0 sec (or w.e) before activating it on the next layout?
https://www.ravenheart.ca/home
Company name changed to avoid Facebook-type shenanigans

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
22
S
6
G
1
Posts: 1,415
Reputation: 4,824

Post » Wed Aug 19, 2015 3:01 pm

I'm actually use something similar, a "wait for signal" that works.

But there is another way more "elegant/easy" to avoid that?

A plugin to simulate any key press will be great, not only the default ones in the behavior of movements, wiht that all this problems dissapears.
B
23
S
10
G
3
Posts: 545
Reputation: 4,442

Post » Wed Aug 19, 2015 3:16 pm

just set your Action1 variable back to 0 in the block of code that calls the action, then perform the action. You don't need the trigger once and it wont run again on the next layout. You don't need the wait this way ether.
B
95
S
33
G
20
Posts: 438
Reputation: 17,640

Post » Wed Aug 19, 2015 3:26 pm

I tried that already and not worked.

I have:
Keyboard X is down = Set variable Action1 to 1
Else = Set variable Action1 to 0

If in the layout i put:
Action1 = 1
-> Set Action1 = 0
-> Go to layout "X"

Still not works, pass various layouts :S . ¿Or i'm doing some wrong?

Actually only work if i have a condition that do:
Action 1= 1 -> Signal "skip"

And to skips layouts i put that when action1 is 1 -> Wait for signal "skip".
B
23
S
10
G
3
Posts: 545
Reputation: 4,442

Post » Wed Aug 19, 2015 8:23 pm

@matriax is there a reason you are using "Key Is Down" rather than "On Key Pressed" ?

on key pressed will only fire once when you press the X key.
Key is down will fire many ticks in a row, even if you think you only briefly pressed the key. (what seems like one press to you is like 10 to the computer since it is running 60 times a second.)
Every tick that the X key is still down will set the Action1 variable to 1 again, and that will cause the Action to get called again (so that could skip several layouts).

Use "On Key Pressed" if you can (unless there is a good reason why you need to let the user hold down the X key).
B
95
S
33
G
20
Posts: 438
Reputation: 17,640

Post » Wed Aug 19, 2015 8:33 pm

@AllanR Because with "On Key Pressed" if you hold the X for some attack the action1 will be 0 instead 1.

I mean, with the keyboard events you can set if is "on press" or "key is down". But how you replicate this two states using "On Key Pressed"?

Or imagine i use other key for jump that depending that how much time you hold the jump is more high, you can't achieve this with "on key press" only with "key is down".

So, for that reason i use "Key is down" plus Trigger once, to make one key press, and "key is down" alone to get the "hold" state.

The problem is that between the layout changes, the "trigger once" is executed on each layout instead remember that the action was did in the other layout.

As i said i had fixed using the "wait for signal" that works perfect, but i don't know if that will generate other problems so better if you or somebody can tellme a more easy/elegant solution :P .
B
23
S
10
G
3
Posts: 545
Reputation: 4,442

Post » Wed Aug 19, 2015 10:53 pm

Sometimes you just have to use 'hack' solutions until you find a more elegant one. We have a couple of those types of solutions running our game atm too, lol.
https://www.ravenheart.ca/home
Company name changed to avoid Facebook-type shenanigans

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
22
S
6
G
1
Posts: 1,415
Reputation: 4,824

Post » Thu Aug 20, 2015 1:53 am

@matriax yeah, I understand the need to use Key Is Down for those kinds of functions. I just wasn't clear on why you would need to hold down a key while changing layouts... but I see there could be possible scenarios for that too.

in the testing I did yesterday, C2 does not realize a key is still down when it gets to the next layout (neither the "Key is down", or "On Key Released" events fired - and I would think that is a bug in C2 (but Ashley might say it is that way on purpose, or too difficult to change now to make it worth fixing). So, you might want to consider filing a bug report and see what he says...
B
95
S
33
G
20
Posts: 438
Reputation: 17,640

Post » Thu Aug 20, 2015 6:30 am

I see, thanks to all for the info.

So, there is anything i'm missing that why is not possible simulate any key press actually with the keyboard plugin in the same way that some behaviours like 8directions movements or the Platform one do?

Adding to the keyboard plugin the option to simulate any key press will make all much easier, why is not done already? , or in the same Plaform/8direction behaviour, why not allow simulate other any key press ¿?
B
23
S
10
G
3
Posts: 545
Reputation: 4,442


Return to How do I....?

Who is online

Users browsing this forum: ajcoppersmith, blue visionary and 4 guests