Example use case:
There are 12 boxes in the scene, indexed 0 to 20. The user can press combinations of any of 0-9 to open each box at its index, ex. press 2 -> opens box at index 2. However, if the user say holds 2 instead of just tapping it, boxes will float in the air, then drop back to the ground when the key is released.
I don’t want to go through and create pressed/released/etc. function callbacks for all 10 digits. That would be 40 tiny functions for one simple action of selecting an index.
- Binding all ten digits to one callback function. So whenever something happens with 0-9, the event will be handled with a general function like numberPressed(), numberReleased(), etc. Problem: I can’t find out exactly which number was pressed. Note that 0-9 may not be 0-9–the user can set it to A-G or whatever–so I can’t hard code a check for a specific number, either.
- Binding them to an axis input. I’ve been attempting to work with this for what must be two days now but there are so many parts of it that are making it nigh impossible–mainly how numbers can come in as an added value if they are held at the same time (ex. press 1 and 2, get 3 when it should mean 12). Not being able to know whether the number has just been pressed or released both fuels this problem as well as being a whole other thing of its own. I tried keeping track of the states manually, but it’s not as easy as predicted, what with the spaghetti values.
Is there another way of going about this? To iterate, I need to know what key was pressed and how it was pressed (tapped/held/released/double-tapped), and I would like to know this without making 40 functions that do the same thing.
I did previously ask this at the answer hub, but got no answers and very few views–numeric selection is a pretty core element in my game so I’m trying again here. Thanks for any help.