Question What can we do with Lua

Ripley

Tutorial translator
Donator
Joined
Sep 12, 2010
Messages
3,133
Reaction score
407
Points
123
Location
Rome
Website
www.tuttovola.org
First, sorry for the extreme noobiness of my post/request.

I think that I, for one, could really enjoy a very general post in this new Lua subforum where someone presents and briefly explains to those who don't know what Lua is, what can be done with it in Orbiter.

I know it's a scripting language ok, I know there's a "Script Interface" chapter in the official Orbiter.pdf documentation, but I also feel it's a rather unexploited/underrated Orbiter "feature".
The only Lua use I saw around (other than what comes with Orbiter default install) is in those scripts mainly written by dgatsoulis in the "Tutorials & Challenges" section.

Thanks.
 
Last edited:

4throck

Enthusiast !
Joined
Jun 19, 2008
Messages
3,502
Reaction score
1,008
Points
153
Location
Lisbon
Website
orbiterspaceport.blogspot.com
Open Orbiter and press the help button :) All the script functions are explained there.

For a short answer, it's a text file that gets interpreted, in real time, by orbiter, and can access it's internal functions.
So you can do almost all that can be done in Orbiter with it, with no need for C++ code.

You can do MFDs or configure vessels with Lua.
For example, you can animate cockpit dials in real-time, automate systems, etc.

I'm working on a Gemini B MFD that handles the reentry sequence, expanding the normal SC3 vessel abilities.
Specifically, I use Lua to create the retrorockets when needed, fire them at the right intervals, jetisson modules, open parachute, etc, etc.
Really powerful.

I guess it can be used to have dummy vessels circling around bases, or some traffic around ISS, for example.

It's NOT well suited for things that require key presses or saving states.
 
Last edited:

N_Molson

Addon Developer
Addon Developer
Donator
Joined
Mar 5, 2010
Messages
9,278
Reaction score
3,247
Points
203
Location
Toulouse
The main pro is that you can run lua - I don't think it has caps in the name right ? - from inside an Orbiter simulation session, it's a bit the Inception of programming :p The obvious application is of course guidance programs for rockets or autopilots that you can run through a Console MFD, which also is quite immersive. You can load a pre-written script with a "run" command through that console, or even enter it "live" (say, if you only need one simple thing). You have an example with the ascent guidance program for the default Space Shuttle Atlantis. It can even display the instructions and their state, which looks cool (and can be handy).

The other way requires to write and compile a .dll (Dynamic Link Library) plugin, which is a Microsoft format, correct me if I'm wrong. It really isn't that hard, but for beginners the compiler (MS Visual Studio) setup itself can be a bit daunting. You can do nearly everything, but a .dll is quite a closed box and you'll have to recompile it for modifications, which can't be done from Orbiter inside. There is a way to run Orbiter through the compiler - aka the debugger - which helps you a bit from going back and forth Visual Studio and Orbiter. But still, having to recompile everything to track bugs is... not very handy. There are however ways to go around that "closed" aspect of the .dll like storing variables into a third-party file (like a .cfg or .scn, which is a mere text file with a different extension). Or you can even program an editor with integrated GUI that allows more flexibility (the Scenario Editor you have in Orbiter is actually a .dll plugin). Also there is the graphical stuff which can - I think - only be handled by a .dll (like panels, virtual cockpits, custom interfaces, even graphic clients...)

Both can be useful, really. Still a lot of devs use .dll because they are professionals that already have an extensive knowledge of C++. Maybe people also think "oh man compiling a .dll looks so pro I'm going to do that !". And - maybe this is the most important point - having a "closed box" can be quite convenient if you don't want people to mess with your own stuff (also solving 'rights' issues in commercial uses - this isn't the case in Orbiter as you can't sell addons, Martins was very clear from the start, which allows the whole thing to stay 100% free -). You can provide the source files with your plugin so that other people are able to recompile it but that is totally up to you. Again it can be professional habit not to share your knowledge for free (though the vast majority of addons devs do share their source files). Or it can even be a lack of confidence, I'd personally would fit in that category as I am a pure hobbyist and can think "oh professionals are going to have a good laugh if they see my very messy way of doing things". You don't have that with lua. AFAIK you can't "close" a lua script in the Orbiter context. I don't know the legal details but lua is "open source" in mind.

Also until very recently lua functions were a bit under-documented and its why it is very interesting to see more interest on that side. It can really allow a lot of people to adapt existing things (typically autopilots) to their needs by replacing variables values. You can do that with the Atlantis sample in a few seconds. Definitively there is a lot of room for tutorials and things like that. Orbiter has become a huge project and we can't expect Martins to take care of everything, even if he wanted that would probably be impossible. So :thumbup:
 
Last edited:

Donamy

Addon Developer
Addon Developer
Donator
Beta Tester
Joined
Oct 16, 2007
Messages
6,906
Reaction score
201
Points
138
Location
Cape
Yes, please more examples.:thumbup:
 

BEEP

Addon Developer
Addon Developer
Joined
Apr 5, 2008
Messages
153
Reaction score
15
Points
18
I'd think that developing community sim resources in an open code format is mandatory as the amounting experience regarding the avoidable obsolescence of cherished and sometimes essential legacy assets has shown. Orbiter is a good example in this particular but it is not the only one. My coding is very questionable and sometimes deliberately so due to development path options and decisions. I'm not ashamed in any way because a critic would be out of place. Community addon development does not need to follow the practices intended for industrial market products. In fact I gave up calling version "betas" as I've found out that these are forever developments. This is a hobby and its done for fun allowing for more creativity and risk taking than in commercial, professional environments. Using the same criteria ( even when pure logic applies) to analyse this kind of software is not only unwise but a waste of time.
 
Last edited:

ADSWNJ

Scientist
Addon Developer
Joined
Aug 5, 2011
Messages
1,667
Reaction score
3
Points
38
I think open vs closed is the wrong argument for lua vs C++. There's tons of C++ in this community that is fully open (including all of my addins, for example). Lua is a fine environment for scripting and prototyping, but is nowhere near as sophisticated as C++ if you want to get into high performance or deeper levels of integration. That said ... if your first steps into giving back to this community are via lua, then I applaud you, and if I can help anyone interested in taking the next step into C++, then PM me.
 

4throck

Enthusiast !
Joined
Jun 19, 2008
Messages
3,502
Reaction score
1,008
Points
153
Location
Lisbon
Website
orbiterspaceport.blogspot.com
It's good to have a solution (Lua) that forces the community to break down the problems into manageable parts.

Most of us don't have much time. So being able to develop something, let's say 30 minutes each day, and get results is important.
Specially for people that don't use C++ or visual studio everyday ;)


Having the source code solves nothing. We do have it. But updating is too complex and time consuming, because Orbiter itself has become complicated.

So its important that more and more people start creating, and have an accessible tool to do so!
 

kuddel

Donator
Donator
Joined
Apr 1, 2008
Messages
2,064
Reaction score
507
Points
113
Let's not make this into a "mine's better than yours" war ;)
I would definitely recommend C++, as I am more used to it.
But I can also fully understand the Lua lobbyists.

Everybody can freely choose what to do
(some things however might still force you into one or the other, but that's fact-driven not opinion-driven)
 

ADSWNJ

Scientist
Addon Developer
Joined
Aug 5, 2011
Messages
1,667
Reaction score
3
Points
38
Kuddel is right ... choose the tool you are happy with, and create what you want. It's amazing to think that behind the video output of this magnificent simulation is an ocean of data and control points for you you do whatever you want. From the simplest of outputs of data (to the exact precision you want), to the most complex of control systems ... it's all within reach from LUA or C++ as you prefer.

There's some learning curve for C++, but you don't need to be a daily programmer and deep guru to learn it, and you can still do it 30 mins at a time, especially with a bit of help to get started. My philosophy is to "pay it forward"... I learnt so much from others in this forum, and I want to repay it by passing on some knowledge to others. Who wants to take me up on this?
 

Face

Well-known member
Orbiter Contributor
Addon Developer
Beta Tester
Joined
Mar 18, 2008
Messages
4,398
Reaction score
578
Points
153
Location
Vienna
The main pro is that you can run lua - I don't think it has caps in the name right ? - from inside an Orbiter simulation session

You can do nearly everything, but a .dll is quite a closed box and you'll have to recompile it for modifications, which can't be done from Orbiter inside.

I think these two statements nailed it for me. Lua is explorable from inside Orbiter itself, while DLLs are generally not. This way, it offers a possibility for non-coders to explore the features of the Orbiter API on the go.

Keep up the good work, kuddel! :cheers:
 

jedidia

shoemaker without legs
Addon Developer
Joined
Mar 19, 2008
Messages
10,861
Reaction score
2,125
Points
203
Location
between the planets
You can do nearly everything, but a .dll is quite a closed box and you'll have to recompile it for modifications, which can't be done from Orbiter inside.

Weirdly enough, that's one of the main cons for me. I like my compile-time type checking :p

It's good to have a solution (Lua) that forces the community to break down the problems into manageable parts.

That's really just a matter of proper encapsulation, though. But of course encapsulation is a major problem for programming beginners, and visual studio project setups tend to drive you nuts when you're not sure what you're actually doing.

That, C++'s godawful include handling which can be an annoying time sink even for professionals in larger projects, and the equally godawful syntax of the STL are what makes the lua option a good choice to get some results fast, especially for beginners.
Until the project becomes too complex and the lack of type checking and a solid debugger start to drive you nuts. As far as I remember, lua didn't really have any type checking at all, not even at runtime. It would just throw weird exceptions if types didn't match, or just acted weirdly when you were unlucky enough for the table you passed actually having the field you were querying, but it meaning something entirely different in this table than in another.
 
Last edited:

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,604
Reaction score
2,324
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
1000% agree. That forces you to structure your work and do some debugging yourself. And that's a great learning process, although time consuming.

Its first of all "Learning by pain". You will NEVER learn this properly by a textbook alone. But a textbook can give you better ideas how to ease your pain of course. ;)

Also, to give a few cents more here: Having the source code available is not the same as making it easy to understand what is going on there. Good examples should have a few comments more than a good developer needs for remembering what he did last summer. Ideally even a short HTML manual to explain things you can't explain by source code alone.
 

LeePalmer

Member
Joined
Apr 7, 2013
Messages
40
Reaction score
0
Points
6
An example luascript example.

Hi everybody.

I am sorry for the necro post,. Oh and the shameless self promotion of an addon. :)

Spotlight MFD Luascript
https://www.orbithangar.com/searchid.php?ID=7142

I was doing this as you guys talking about things above. I thought I
would finish it before release.

Also RCS Attitude is luascript. config\mfd\attitude.cfg

Regards

Lee
 
Top