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

0 favourites
  • 4 posts
From the Asset Store
Total customisation of the input! You can combine inputs from all peripherals. Make your game accessible for everyone!
  • I there,

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

    Basically I have :

    [quote:2hrbkc1c]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 :

    [quote:2hrbkc1c]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 :

    [quote:2hrbkc1c]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 : mediafire.com

    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 <img src="{SMILIES_PATH}/icon_redface.gif" alt=":oops:" title="Embarrassed" />

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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...

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)