How do I make this Else statement work with keyboard input ?

Get help using Construct 2

Post » Tue Jun 27, 2017 6:03 pm

Message: Semoreh can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
I there,

I've encountered a problem using an "Else" expression.
Basically I have :

Global Number variable = "1"
IF (variable = 1)
--> Key "Enter" is pressed --> Call Function Addtodebug "AAA"
ELSE
--> Key "Enter" is pressed --> Call Function Addtodebug "BBB"


Problem is : if I press Enter... I'll see "AAA BBB" in the debug text box oO
I've been using construct 2 for a while now, and this really surprises me. Why doesn't the "Else" expression filter the keyboard input there ?

Also it seems to bypass everything else in the "Else" subevents because if I add this :
IF (variable = 1)
--> Key "Enter" is pressed --> Call Function Addtodebug "AAA"
ELSE Call Function Addtodebug "Random Text"
--> Key "Enter" is pressed --> Call Function Addtodebug "BBB"


If I press Enter... I still see "AAA BBB" in the debug text box. The "Random Text" part never appears.

And to put the nail in the coffin : everything works PERFECTLY if I'm using a Gamepad and Gamepad inputs. Thus :
IF (variable = 1)
--> On gamepad 0 Button A is pressed --> Call Function Addtodebug "AAA"
ELSE
--> On gamepad 0 Button A is pressed --> Call Function Addtodebug "BBB"


We see "AAA" in the debug box as expected. The Else statement works just fine.
Does this mean all inputs are not considered equal ? How are keyboard inputs different from gamepad ones ?

A simplified CAPX illustrating this conondrum can be downloaded here : https://www.mediafire.com/?9uo4bve9guz1wfh
Thanks in advance for your help, I lost a few hours isolating this problem and I'm scratching my head as to why it doesn't work :oops:
B
5
Posts: 12
Reputation: 258

Post » Tue Jun 27, 2017 6:09 pm

B
45
S
15
G
73
Posts: 2,002
Reputation: 43,386

Post » Tue Jun 27, 2017 6:15 pm

On XXX pressed is a trigger. You shouldn't bury them under normal logic as they are triggered outside of the normal C2 cycle. Always best to put them at the top level and decode your logic underneath, as plinkie has done.
ImageImageImage
B
71
S
21
G
220
Posts: 3,646
Reputation: 123,721

Post » Tue Jun 27, 2017 6:26 pm

Hey Plinkie, thanks for your answer :)

Yes it works like that of course, but that doesn't explain why it doesn't work the other way around. It's more a question of principle at this point.

Plus I shared a very simplified Capx, in my actual project it is easier to check for the variable and then check for the input. It worked perfectly with a gamepad and when I tried to duplicate the events to handle the keyboard it started bugging.
I could change everything of course, but I don't want to do it before I know why it wasn't working in the first place ^^

Blackhornet >> Thanks for your answer. I understand what you say, but I've coded small games before with lots of buried triggers (keyboard and gamepad related) and it worked just fine :/
Now that I'm looking at one of my old projects, I realise I never used any trigger of the sort underneath an "Else" statement though, so everything seems to come from there...
B
5
Posts: 12
Reputation: 258


Return to How do I....?

Who is online

Users browsing this forum: marc254 and 4 guests