jkgarner
Posts: 174
Joined: 4/30/2020 Status: offline
|
I create scenarios through Lua all the time... It can turn into a lot of code, which means you might want to consider organizing the code into re-usable chunks and loading them first. But don't worry about that at first. 1st: Get yourself a tool that does context highlighting for Lua. Many us vscode, I use Notepad++. Both are free. vscode seems to work better with a standard Lua environment. As we are developing Lua scripts in a limited environment, I have found Notepad++ sufficient. 2nd: EVERY time you write something useful, or find something useful on the forums, copy it into a local file with documentation sufficient to remember what it does. Generally this is at minimum, a description of what the function does and a listing of the parameters, parameter types, and parameter meaning/usage. Place all this code in a single location. This can be a single file, or a collection of files in a single directory. The choice here is yours. 3rd: Understand how to set up an event at ScenarioLoad Time. There is help for this on the forum. The first thing you will want to do is load up any lua functionality that you have created during this ScenarioLoad event. 4th. You must determine if this is an initial load (user staring the scenario for play) or a reload of a saved state. In the general case, this can be done by examining the scenario time and comparing it to your start time. if they match it is probably a new load. If it does not match, they have started running the scenario. This fails if the player opens the scenario and closes and saves without pushing the go/run button. The way around this is to store a loaded value with the ScenEdit_SetKeyValue function called during the ScenarioLoad event. 5th. You will need to follow the same steps in Lua that you would normally follow with the GUI... start with the sides, then postures, then create units, then events and so forth. This is where you create a lot of code. 6th. Test the scripts by running them from the console in a blank scenario. When it all works, tie the code to the LoadScenario event. I have build a mechanism for creating a library of Lua code and load it. A version of it is available on the Forums at: https://www.matrixgames.com/forums/tm.asp?m=4831042 As KnightHawk75 said, what you are attempting IS possible, though it may stretch your coding ability. There may be a few times when you may need to adjust your thinking a bit as about 98% of the GUI's capability is implemented as Lua functions. You will get very familiar with the interface and the CommandLua documentation site: https://commandlua.github.io/index.html And take it one step at a time. Good Luck!
|