How do I clean up command inputs?

0 favourites
  • 5 posts
From the Asset Store
Supports keyboard, mouse and gamepads. Supports several gamepads at once.
  • Weird title, I know.

    Here's my dilemma:

    Building a fighting game prototype, trying to streamline the handling of inputs. I'm translating device commands so that it'll be easier to handle multiple types of input (Keyboard, Gamepad, Touch if I so will it.)

    The problem I've run into is that I'm forced to use a lot of nesting to get it to work as it should. I've included the CAPX , so you can see my work so far. The eventsheet with the offending events is in the Control sheet, under Layer 1: Raw Input Keyboard.

    The logic behind what I'm doing is that if you press a key, as long as you aren't pressing an opposing key, it will alter the value to it's correct state. If you're familiar with the Number notation used in the fighting game community, it's like that. (Explanation: Look at your number pad. 2, 4, 6, and 8 correspond to a cardinal direction and 1, 3, 7, and 9 are diagonals. 5 is neutral.)

    The way I wanted to do it is if you're pressing left or right, the value is set to 4 or 6. Then if you press up or down, it will either add 3 or subtract 3 from the value, while it's held. Thus, if you're holding right (6) and holding up ( X +3 ) you'll get 9, which is up-right. And if you're just holding up, it should be Neutral (5) + Up (X+3) and equal 8, which is just Up. If you let go of Up, it should return to it's value pre-Up, which would be 4, 5, or 6 respectively.

    Needless to say, that didn't quite work out right. So I ended up making complicated nesting to get it just as it's supposed to work, and just set values instead.

    It looks ugly as sin to me, and I'm asking if there's a cleaner way of doing it. Trying to keep the number of events to a minimum. I teach a class of 11 year olds development with Construct2 for my summer job, and I want to keep it under 100 events so that they can take it home and mess with it in the free version.

  • I'm guessing you're looking to set a numerical value to your input to mirror a keypad. This is simpler - I've reduced the input to 4 lines. There are probably other ways of doing it, of course.


  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • My take on this issue..

    Although it really doesn't cut down that much on the code, it only works with triggered events..

  • Actually, with some minor adjustments it seems it is exactly like you asked for in the first post, haha..

    Simplified it!

  • I am very grateful! Exactly what I needed!

    You guys are awesome. This also gives me some better insight for the rest of the project.


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