AKA_Clutter Posted September 29, 2021 Posted September 29, 2021 (edited) Hi all, As the title suggests, this isn't directly relat4ed to DCS or building missions. I am in the process of trying to teach myself lua so that I can 1) understand the DCS API, 2) understand MIST, 3) understand MOOSE, and 4) and write my own scripts. I have lua installed and am trying to get an IDE (or something like that) where I can write simple lua scripts to learn the language. I have Eclipse-LDT and VS Code (with the sumneko lua extension and the Actboy168 Lua Debug extension). I'm having issues (different)with both. What I would like to be able to do is type in the code, then run the code to see how it works, or where the issues are. So, given the above, what would you recommend as an IDE to learn lua with, and are there guides to help me get them working. Thanks, Clutter Edited September 29, 2021 by AKA_Clutter ---------------- AKA_Clutter Win 10 Pro, Intel i7 12700k @4.6 GHz, EVGA RTX 3080 FTW, Ultra 64 GB G.Skill DDR4 3600 RAM, Acer 27" flat screen, HP Reverb G2, TM Warthog HOTAS with Virpil warBRD base, MFG Rudder Pedals, Virpil TCS Rotor Base with AH-64Dcollective, TrackIR 5 Pro w/Vector Expansion, PointCTRL.
UncleZam Posted September 29, 2021 Posted September 29, 2021 (edited) As a big fan of short feedback loop programming, I would suggest just start the lua interpreter to get into interactive console. There you can type lua code statements/expressions and see the results immediately by pressing enter. You can inspect variables and define multiline functions. Just mess around to get the feel of the language. Remember that DCS still uses lua version 5.1, so you may want to install that version for full compatibility. Edit: of course this goes only for learning the Lua language. Connecting the interactive console to DCS session is a whole different story. Edited September 29, 2021 by UncleZam
AKA_Clutter Posted September 29, 2021 Author Posted September 29, 2021 8 minutes ago, UncleZam said: Edit: of course this goes only for learning the Lua language. Connecting the interactive console to DCS session is a whole different story. I've done that some and my primary goal is learn lua as well as doing scripting for DCS. I know that you can do "do file ... ... " to execute a file in the shell. However for nested ifs and such, it seems like an IDE would be better in the long run. Can you connect the interactive console to a DCS session?? Assuming that is true 1) WOW, and 2) WAY way above my head at the moment. Thanks for the response. ---------------- AKA_Clutter Win 10 Pro, Intel i7 12700k @4.6 GHz, EVGA RTX 3080 FTW, Ultra 64 GB G.Skill DDR4 3600 RAM, Acer 27" flat screen, HP Reverb G2, TM Warthog HOTAS with Virpil warBRD base, MFG Rudder Pedals, Virpil TCS Rotor Base with AH-64Dcollective, TrackIR 5 Pro w/Vector Expansion, PointCTRL.
UncleZam Posted September 30, 2021 Posted September 30, 2021 6 hours ago, AKA_Clutter said: However for nested ifs and such, it seems like an IDE would be better in the long run. This is true. I am coming from Python and learning Lua, and have used Zerobrane Studio and Vim+plugins. The former is quite neat lightweight editor, and I kinda liked it. Vim on the other hand is good if you know it or are really interested in learning something different. 7 hours ago, AKA_Clutter said: Can you connect the interactive console to a DCS session?? Assuming that is true 1) WOW, and 2) WAY way above my head at the moment AFAIK it is not possible with Lua builtin console, but it is possible with some other tools. Glad you asked, because I am currently developing one. It is based on Jupyter framework, is this familiar to you? Jupyter allows for really cool interactive tools, ranging from console to rich media Notebooks and Lab, which is kind of IDE. The tool I am developing is still a bit rough and not public yet, but I am planning to publish it as open source soon. If you are interested, you could take a look at Jupyter framework in the mean time. I am basically developing DCS-kernel for the Jupyter. I am happy to tell more, if there's interest.
AKA_Clutter Posted September 30, 2021 Author Posted September 30, 2021 LOL I'll have to pass on the "jupyter framework" a pass atm. I have lua, python and C++ books I'm trying to plow through. ---------------- AKA_Clutter Win 10 Pro, Intel i7 12700k @4.6 GHz, EVGA RTX 3080 FTW, Ultra 64 GB G.Skill DDR4 3600 RAM, Acer 27" flat screen, HP Reverb G2, TM Warthog HOTAS with Virpil warBRD base, MFG Rudder Pedals, Virpil TCS Rotor Base with AH-64Dcollective, TrackIR 5 Pro w/Vector Expansion, PointCTRL.
UncleZam Posted September 30, 2021 Posted September 30, 2021 38 minutes ago, AKA_Clutter said: LOL I'll have to pass on the "jupyter framework" a pass atm. I have lua, python and C++ books I'm trying to plow through. That's a lot of reading, but useful topics you got there . I should still mention that you can think of Jupyter as a interactive CLI, UI or IDE for programming languages (I think it got all three you mentioned) as kernels. So you can use it as an application, like it is mostly used. But being modular, it can be extended with new kernels like DCS-lua.
AKA_Clutter Posted October 1, 2021 Author Posted October 1, 2021 Humm, will have to look into it one day soon. ---------------- AKA_Clutter Win 10 Pro, Intel i7 12700k @4.6 GHz, EVGA RTX 3080 FTW, Ultra 64 GB G.Skill DDR4 3600 RAM, Acer 27" flat screen, HP Reverb G2, TM Warthog HOTAS with Virpil warBRD base, MFG Rudder Pedals, Virpil TCS Rotor Base with AH-64Dcollective, TrackIR 5 Pro w/Vector Expansion, PointCTRL.
HC_Official Posted October 1, 2021 Posted October 1, 2021 (edited) @AKA_Clutter to save you literally thousands of hours of frustration watch this video and set this up so you can load script while the mission is running This is NOT specific to using MOOSE , but for any dcs lua script you might be trying out 1. edit script 2. save script 3. execute script in dcs (without having to restart the mission) ....... then go to step 1 because you made a boo boo in the code Edited October 1, 2021 by HC_Official 1 No more pre-orders Click here for tutorials for using Virpil Hardware and Software Click here for Virpil Flight equipment dimensions and pictures. .
AKA_Clutter Posted October 1, 2021 Author Posted October 1, 2021 4 hours ago, HC_Official said: @AKA_Clutter to save you literally thousands of hours of frustration watch this video and set this up so you can load script while the mission is running This is NOT specific to using MOOSE , but for any dcs lua script you might be trying out 1. edit script 2. save script 3. execute script in dcs (without having to restart the mission) ....... then go to step 1 because you made a boo boo in the code WOW! Not what I was asking, but this is GOLDEN!!! Will save a ton of time! Thanks!! ---------------- AKA_Clutter Win 10 Pro, Intel i7 12700k @4.6 GHz, EVGA RTX 3080 FTW, Ultra 64 GB G.Skill DDR4 3600 RAM, Acer 27" flat screen, HP Reverb G2, TM Warthog HOTAS with Virpil warBRD base, MFG Rudder Pedals, Virpil TCS Rotor Base with AH-64Dcollective, TrackIR 5 Pro w/Vector Expansion, PointCTRL.
cfrag Posted October 1, 2021 Posted October 1, 2021 (edited) If you don't mind, two suggestions: Only use 'Do Script' as opposed to 'Do File' with any code that you are still editing (unless you can dynamically load). I'm using Notepad ++ for all editing, and then us copy/paste to paste in the script into the dinky text dialog. Definitely not ideal, but it beats the nagging worry that for some reason ME screwed up and loaded the file inside the mission as opposed the one you just modified. Also be aware that DCS desperately needs a syntax checker for Lua. I've not yet found an ideal solution (requiring me to repeatedly start missions, end, edit the file, copy/paste, restart mission - the 'dance' as referred to earlier. Can't do dynamic loading because usually, the script I'm developing is the mission script itself) for silly stuff like misspelling 'then' or forgetting an end. If you have found an easy help for validating the syntax (just the syntax, no semantic checks required), I'd be grateful. Also, I recommend you understand the basics of DCS Lua before you inundate yourself with mist and moose. They are great frameworks, and understanding them is much easier when you know the idiosyncrasies of DCS before you attempt to understand why mist/moose do certain things they way they do. Now, there are many ways to skin a cat. One is to write small script that get get invoked via ME triggers. That can be an efficient approach, and tends to break up your mission code in many small and reusable blocks. I tend to write differently: I have a library of code and ME extensions that I load when teh mission starts, and a mission script that runs like any other app in the background; it is self-contained and does not rely on triggers (except to be started at the beginning of the mission) For a bare-bones self-contained scripting environment, you usually only need to implement two things (maybe even just one): a repeating update() method so that DCS invokes you code regularly. You do that by scheduling an invocation to your own update method (you can call it whatever you please, it's called during the DCS script loop) via timer.scheduleFunction(). You do that once in Lua outside your fnction definitions; and at the start if your Update invocation, you simply re-schedule a call to itself. Now your code is called regularly every so often (you define the interval yourself). In this method you usually monitor the units that are important for you, and act accordingly subscribe to the world event handler, so your code gets invoked whenever something interesting happens. You do that by invoking world.addEventhandler() once from Lua to add your own function, and from that point on, your code is invoked whenever some very specific, defined by DCS, events happen Except for server events (that I highly recommend you postpone until you feel more comfortable, but that aren't difficult to understand later) above will allow you to do 99% of everything you want in your missions. Once you manage to write code that can reliably be invoked to handle specific events (like a player plane taking off or getting killed), and can monitor other stuff (like when a player plane get closer than a specific distance to an AI unit), take a peek at mist. Then marvel at some really cool tricks that would have taken you years to come up with, and that will give you additional ideas to improve your own code. Then start coding in earnest - and use moose if you want to short-circuit building your own framework. Edited October 1, 2021 by cfrag
AKA_Clutter Posted October 1, 2021 Author Posted October 1, 2021 @cfragI'm always up for suggestions. Thanks for taking the time to respond. I have dabbled in developing a few scripts using the DCS Lua API (Is that the correct way to refer to it?). Attached is one such script. Not pretty, and I'm sure it isn't efficient, but it does get the job done. And I learned a lot in doing it. I guess my thought is to lean lua fairly well before diving too deep into making scripts, as well as diving into MIST and MOOSE. May not be the shortest path, or the best, but should be fun. I have Notepad++ and have used it for years, for many different things and think it is great. However, to learn lua I think that I want something more like an IDE. My issues is that I don't know enough about them to get them configured correctly. Hopefully I['ll stumble onto something sometime. Simple_Script_1.txt ---------------- AKA_Clutter Win 10 Pro, Intel i7 12700k @4.6 GHz, EVGA RTX 3080 FTW, Ultra 64 GB G.Skill DDR4 3600 RAM, Acer 27" flat screen, HP Reverb G2, TM Warthog HOTAS with Virpil warBRD base, MFG Rudder Pedals, Virpil TCS Rotor Base with AH-64Dcollective, TrackIR 5 Pro w/Vector Expansion, PointCTRL.
cfrag Posted October 3, 2021 Posted October 3, 2021 On 10/2/2021 at 1:56 AM, AKA_Clutter said: I have dabbled in developing a few scripts using the DCS Lua API (Is that the correct way to refer to it?). Attached is one such script. Not pretty, and I'm sure it isn't efficient, but it does get the job done. And I learned a lot in doing it. Nice - am I right in assuming that this is invoked using a trigger? The next step would be to have the code executed by your own small code that monitors the conditions and invokes your final code when the situation is right (and may update you on your intermediate time/speed). That being said, the way you are doing it right now usually is much more serviceable for other people who are not as knowledgeable in Lua as you and want to edit your mission
AKA_Clutter Posted October 3, 2021 Author Posted October 3, 2021 Thanks, Yes, it is executed by a set of triggers and uses zones. My intent is to try and script as much of this as possible so that it is more generic. I have a group of triggers for each helicopter type (and 4 of each). I've included some flags to easily change the "goal time". Once I finishing testing this latest change, I plan on putting up for others to try and tweak as they wish. As far as more scripting goes, I am thinkin g of a scripts with the F10 menu where you can choose to practice Hot LZ landings. And it needs to allow for any existing helicopter type. I think it is doable, but I have a LOT to learn about LUA and the DCS API before I get to the finish line. Thanks for the encouragement. 1 ---------------- AKA_Clutter Win 10 Pro, Intel i7 12700k @4.6 GHz, EVGA RTX 3080 FTW, Ultra 64 GB G.Skill DDR4 3600 RAM, Acer 27" flat screen, HP Reverb G2, TM Warthog HOTAS with Virpil warBRD base, MFG Rudder Pedals, Virpil TCS Rotor Base with AH-64Dcollective, TrackIR 5 Pro w/Vector Expansion, PointCTRL.
Recommended Posts