How to set up an Enum for my inputHandler

0 favourites
  • 2 posts
From the Asset Store
A whole set you need to create a gorgeous winter 2d game
  • Hey all,

    Just wondering if there's a way to set up an Enum. I've created an input handler that reads the input state of 16 different inputs ( replicating a gamepad without being tied to the Gamepad plugin ).

    This handler uses a string that stores all 16 states, separated by commas, so when I test an input, I just tokenAt() the index I want for the specific input I want to test. Is there any way to tie these index values to actual string names for readability and convenience?

    I'm sure I'll remember the index order of all my inputs eventually... but it'd sure be nice to just type the name of the input I want and have the appropriate value serve as the actual index to be read from.

    example:

    current = "int( tokenAt( obj_inputHandler.inputState, 0, ", " ) )

    desired = "int( tokenAt( obj_inputHandler.inputState, Up, ", " ) )

    Is this possible or will have to come up with a workaround?

    Thanks in advance,

    Brent

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You can create a bunch of constant variables: UP=0, DOWN=1 etc. And then use these constants in tokenat() expression.

    But I would suggest switching to a dictionary instead of comma-separated list. It will be easier to work with, easier to update and better for performance.

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