TL;DR
Add a feature to the Lua API that allows scripts to get a player's current inputs/keypresses, or to listen for something like an on_input_released event.What ?
I've just run into a brick wall trying to implement a mod feature that involves holding down RMB, because currently Factorio does not allow scripts to detect whether a button is being pressed in any way besides the initial press of a CustomInputEvent. As a result, many different kinds of features are impossible to mod in simply because they involve some kind of continuous input.For example, it is impossible for this reason to implement a rightclick alt-fire mode for weapons that can be fired continuously just like the vanilla primary fire by holding down the button. There needs to be some kind of way to detect if the player is still holding down the alt-fire button (or alternatively to detect them releasing it) for this to work, but there isn't.
After some thought, I see two main possibilities for allowing scripts to detect if inputs are being held or released :
- Option 1: Add something like a player.get_inputs() method, which would return an indexed list of the custom inputs currently being made by that player.
Example script fragment using such a method:
- Option 2: Add some kind of on_custom_input_released event, which would trigger when a player stops making a custom input and would contain the index of that player and the name of the input they released.
Example script fragment using such an event:
Option 1 seems like the cleanest and most convenient approach to me.
Why ?
Adding a method to the Lua API for reading a player's current (custom) inputs would open up all those currently-impossible-to-implement ideas involving continuous or held inputs, giving modders a great new tool to work with for what from the outside seems like a comparatively minor development cost.Just over the past couple weeks the Lua API has received some huge features I had been silently craving for ages (like EntityPrototype.indexed_guns and EquipmentGrid.unique_id) and these have made a huge difference for me. I really think something like a player.get_inputs() method would be a similarly fantastic addition/improvement for the API.
I hope to see it in the game some day :D