AKA_Clutter Posted September 13, 2024 Posted September 13, 2024 (edited) How far down the Lua rabbit hole should I go? Reprised Hi all, This is a follow-up to the thread that I originally posted to ask the question about how far down the lua rabbit hole I should go. As that thread has over 400 views and a few response (the comments were on point), none really addressed what I was looking for. So I thought I would take my shot at it and see what kind of feedback I got. https://forum.dcs.world/topic/355021-how-far-down-the-lua-rabbit-hole-should-i-go/ The primary responses were 1) you don’t need to go very deep, or 2) find some examples and modify to your needs. Both are on point. For simple things you don’t need a lot and there is no better way to learn that grab something and start modifying it to meet your needs. @Zyll responded that you don’t need to go very deep to be effective. He recommended being able to expertly traverse table and learning the API will get the biggest bang for the buck. MOOSE was also in his response, and from what I’ve read and seen on YouTube, one can do a lot without an in-depth knowledge of lua. They have a lot of example scripts to use MOOSE that I think you can make it a good starting point. I will note that the MOOSE User Guide 1.0 has a good break down under “intermediate scripting” of what one should know. As part of this they suggest that one reads chapters 1 – 4 of the Lua Manual (Edition1). OK, so here is my thoughts on the lua and how far down the rabbit hole to go. Again, my goals were to learn the language, to understand the DCS API itself, and write scripts. Lua Basics Obviously, you will need a detail knowledge of ALL the basics such as; 1. the general syntax of the language, 2. types and variables (numbers, strings, Boolean), 3. valid variable names, 4. reserved names (e.g., and, or, for, etc.), 5. expressions (mathematical, relational, logical, etc.) 6. concatenation operator “..” 7. precedence 8. scope of variables and blocks All of these are pretty easily picked up as they are used all the time. Control Structures These will be used often and as such you will need (and gain through usage) a detail know of most if not all of these. 1. If then else, else if statement – This is used all the time to determine when the script should do something based on the state of a variable. 2. While statement – these will be used although I don’t think as often as the if then else statement of the for statement. 3. For statement (numeric) – This, along with the if statement is used ALL the time. The numeric for is pretty straight forward. 4. For statement (generic) – One of the KEY concepts that you will need to know. Discussed in more depth below with tables. 5. Break and return statements – These will be used a lot as well. They can appear in any of the control statements and in functions. 6. Repeat statement – I haven’t used this much and not sure there is much need. I know hat it is but not near as familiar with it’s usage as the other Functions Functions are used everywhere. You will get to know these in detail. Regular functions, nested functions, functions as part of tables and metatable. Alos you will need to know how to pass items to function in various manners (single variables, tables ,etc. Tables Tables are THE data structure of lua. They are used everywhere in DCS. DCS uses classes and objects extensively, which are tables. To quote @Zil from the other thread: Expertly traversing tables (hint: everything in Lua is pretty much a table) is a must. Generally, the generic for (either in ipairs or in pairs) is used to traverse tables. I’m still trying to wrap my head around how these actual work on complex tables containing data, functions and other tables. Object Oriented Programing, Classes and Objects A good understanding of OOP, Classes and Objects will make life a lot easier. These are essential to understanding the DCS API and everything that Grimes, and others have documented, on Hoggit and other sites. This will help in understanding the “self” keyword, the “:” operator, as well as other little oddities. My guess (and it’s only a guess at this point in my script development history) is that for intermediate levels scripts you won’t be building your own classes and objects. It’s also my guess is that more advanced scripters, and certainly those doing MOOSE do make their own classes/objects. Metatables/metamethods Like OOP, Classes, and Objects understanding these, different types (e.g. __index) will go a long way in understating the DCS API and what you see in other scripts. Coroutines I worked through a couple of examples of this in lua itself. I’m not sure if these will actually be used in scripts. I don’t plan on spending much time. Debugging tools. I have just started to scratch the surface on this subject. Using pcall() and xpcall() can help in not having the mission crash due to an error and it can provide more information. io interface Yup, that is if you plan on trying to output/retrieve data. I’ve used this to generate reports associated with some random flags and unit generation. And there are plenty of larger efforts (e.g., Liberation, Pretense, etc) that use this to save the state of a mission at the end of a session. Standard Libraries I have run into a few of these, but they are pretty easy to pickup and understand as you go along. Other stuff There are TONS of other more complex/detail things in lua and the lua manual. Will those be needed? Who knows. If one is more than just a part time scripted, then probably. But all of that will come with time. Wrap up Ok those are my thoughts. I would love to see other’s thoughts and comments. Edited September 13, 2024 by AKA_Clutter add a little 4 ---------------- 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.
rob10 Posted September 14, 2024 Posted September 14, 2024 As usual, the answer is "it depends" . Depends very much how much (and what) you want to do. I have dipped into direct LUA a bit and some of the mod versions like MOOSE and MIST a bit, and it's amazing how much you can do with just a little bit of knowledge (helps if you have some programming knowledge to allow you to grasp concepts and different ways to do it). Examples and looking at other missions are a great way to learn since LUA can definitely be intimidating to get started into. Good post above! 2
cfrag Posted September 14, 2024 Posted September 14, 2024 (edited) 11 hours ago, AKA_Clutter said: This is a follow-up to the thread And, if I may say, a nice, succinct summary of Lua. Thank you for that. I believe the answer to your question "how deep should I go" lies in answering the question "do I want to know 'how' or 'why'?". Let's look at an analogy. Many people know how to make a fire. They can use this knowledge and make many fires, and over time they learn what works well and what doesn't, and they become very adept at making fires. This has worked well for humanity for millennia and served us well. And then there are people who delve further, trying to understand the why. Why does making a fire it work, what are the components, why does this work, yet other stuff does not? Understanding the intricacies and how components interact allowed us not only to make better fires, but, ultimately, split the atom and fry breakfast bacon (the latter of which is still more important to me than the nuclear stuff). So, understanding "how" mission scripting works boils down to looking at code patterns, and cleverly imitating them, stringing together bits of code, noting what works and what doesn't and gradually learning how to put some unrelated bits and pieces together so that you can eventually accomplish impressive things. You don't know exactly why it works, there's still lots of mystique (what's this '_' doing in a for loop?) -- the important thing is that it works, and that's good enough. Not to be too subtle here -- from what I see of DCS's API, I get the impression that some of ED's fine people use that same approach to designing the DCS API... If you choose to go deeper into the rabbit hole, and here's DCS's particular challenge and the reason for my unsubtle dig at the kind people at ED, you may soon discover the why. Now, with DCS, there are two parts of this: Lua and MSE (Mission Scripting Environment) API. You appear to have left the nuts and bolts of Lua behind you, the whys of Lua scripting are known to you. That rabbit hole probably won't go much further (maybe metatables, but that's really no longer relevant for our discussion). What remains to learn are the particulars of how DCS's game engine fits together, and how it interacts with Lua through its MSE API. Unfortunately, from my personal view, that API has terrible design flaws, and to understand the why, you will first have to suss out what does not wok even though it should, and then accept that you won't understand why it won't. It just doesn't. That's part of the discovery, and it's an integral part of the DCS rabbit hole. The API is riddled with inexplicable really, really bad idiosyncrasies. You are now through the looking glass, deep in Alice's abode. There are wonders to discover, and knowing the how nots and whys of this wonderland can be worth the effort. It will allow you to craft missions that you would never be able to build otherwise, yes. But with this, like so many other deep excursions, the journey is the reward, your new abilities will not cover the cost. So how far should you go? As far as you are having fun. You are already way past the required minimum. Welcome to wonderland. Now, let's go and look for the Mad Hatter. I hear he lives in a a warehouse API, having tea at 1800 sharp. Edited September 14, 2024 by cfrag 3
AKA_Clutter Posted September 14, 2024 Author Posted September 14, 2024 @rob10and @cfrag, Thanks for the responses and kind words. "It depends" sums it all up! And I am generally someone who wants to know "how" and "why". Picking up a written script and trying to tweak to you needs is a great way to start to learn both lua and the MSE API. I too have used MIST and some of "canned" scripts (e.g. cfrag's slot blocker) but haven't tried MOOSE yet. Since I am trying to teach myself programming, lua, and know the how and why (as best I can), I thought it would be best to try and do as much as I can via the API with MIST/MOOSE/CTOD as a crutch when necessary. @cfrag I've been crawling around in the MSE API, and I couldn't agree more. It is a much more complex and convoluted rabbit hole with some narrow passages, and dead ends. The Hoggit Wiki documentation has been a godsend. At times, I have to read it multiple times before it dawns on me actually what it is saying I still marvel at what all have done with things like CTOD, MIST, MOOSE, and things like Pretense, Liberation (although C based a lot), Blue Flag and so on. I think I am on page 5 in a book as big as "War and Peace". I'm still in the "fun" stage. ---------------- 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