Search the Community
Showing results for tags 'lua language'.
-
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.