Help. How to associate a LUA function to a keypress?

ziggybcn

Chieftain
Joined
Aug 22, 2018
Messages
2
Hello!

I'm playing with Civilization VI modding and I would love to know if there's an easy way to associate a LUA function to a specific key press in the game.

I've already written the function in FireTuner, but I would like to make a mod that allows this function to be called when a given key press is triggered by the player.

I've tried to find out how this can be done in the forums, but I've been unable to find an answer.

Thanks!

(And hello, this is my first post here)
 
There's no "easy" way to do this. If your function is a new action for a unit to do, you could add the function into the UnitPanel.lua file and replace the original version of UnitPanel.lua by Importing your customized version into the game's VFS system. But you would probably also need to edit the UnitPanel.xml file as well, and import your customized version of this xml file along with the lua file that goes together with it.

Otherwise you'd need to create a new user interface with a new pair of Something.xml and Something.lua to create the interface needed to tell the game what to do with the keypress, and under what conditions.

GameplayScripts don't pay attention as a general rule to UI or keypresses, and many of the methods needed to create and hide a new UI panel would not work in a GameplayScript.

FireTuner is a hybrid beast, and what works in FireTuner does not always work as a mod without some major re-structuring of the code. FireTuner can implement many methods that are a hybrid of UI Context and Gameplay Context for lua files. But from a mod you cannot mix these methods. You can only use that which is valid for a UI Context within a UI script, and that which is valid for a Gameplay Context within a Gameplay script.

You cannot get around these issues of the differences between UI and Gameplay contexts by directly editing and saving over the top of the game's base lua files.
 
Thanks LeeS! Nice explanation. I've already been playing with the visual studio modding tool. Any advise you could give on how to start the creation of a new user interface to accomplish the keystroke idea, would be very appreciated.

Best,

Manel.
 
Back
Top Bottom