MobiFlight Community Support

Welcome to the forum for MobiFlight! Feel free to reach out to the community in case you have questions, issues or just want to share great ideas or details about your latest home cockpit project.

You like MobiFlight? Donate via PayPal and support the MobiFlight development. Thanks! 

From: Napier, New Zealand
Posts: 11
Where can I find tutorials that demonstrate the use of Lua Macros and/or how to utilise the "Compare" functionality of Mobiflight?
D J Wilkinson
2019-12-27 10:09
From: ETSI, Germany
Posts: 3302

At first.... Do you mean the "LUA Macro PlugIn" from Mobiflight od do you mean the Macros itself ?

The PlugIn in Mobiflight is just a implementation of the Controll Offsets ( FSUIPC) to Run/Stop a Macro via Mobiflight
Without that tool Lua Macros must be controlled in FSUIPC and that need Keypress or Joybuttons .....
With the PlugIn you can directly set a Input (Button e.g.) to a comand that will start/stop the Lua Scripts.

Syntax is explaned here....

If you talk about the Lua Mcros itself..... THIS is not a part of Mobiflight. This is simply usage of LUA Scripting Language.
Google for Guides, Tutorial or lots of Books to lear programming in Lua.
Also check the FSUIPC Manual for Programmers and Advanced Users. There the Basic things are explaned, too.

About Compare.

Compare Tab is basicly self explaned and till now there exist no full tutorial.
The Compare is just a IF-THEN-ELSE Function.... With the posibility to use "String" Characters on output side.

Simply explaned.....
- In the First field "IF" you define a condition with the operator.... For Example "If Raw Value is bigger then 5" you need ">" Operator and "5" in the field.

- in the THEN Field you define WHAT should be executed if the upper condition is TRUE .... In Our Example if the Raw Value is bigger then 5.
You can write here for example " 999" .... That means if Value is bigger 5 ( 6,7,8,9,and so on) then Mobiflight will always show "999" instead of the current Value.

- in the ELSE Field you define what should happen if the upper condition is FALSE ..... In Our example if Raw Value is 5 or less.
If you use "$" Symbol here or let the line Empty then Mobiflight will simply show the original Value. If you make a Entry then Mobiflight show that Data instead of Raw Value.

Additional Info:
You can use Strings here.... For Example you say in then field "hello" then Mobiflight will write "hello" on a Display if condition is true.
You can use formulas here.... So you can create deeper funtions when you use in the THEN or ELSE field a formula like "if($=1,22,33)"

If you need more help here please tell me WHAT you need...... Then i can tell you how to set Compare for correct result !
Good Luck !
2019-12-27 12:58
From: Napier, New Zealand
Posts: 11
Hi there pizman82,
Firstly – a very big thank you for such a prompt and full response.

Now that I have investigated all the documents you referenced my head is spinning!
Having downloaded a LUA IDE and followed through a tutorial to the “test” pages that I couldn’t understand or get any response from I am thinking “Is there another way?”

Therefore my original post is re-submitted as follows:-

By reading carefully through your most helpful responses to posts by other people I have managed to get all my flaps and gear LED’s running as they should with just one little detail relating to the flaps UP position indicator LED remaining unresolved.
By adapting one of your beautifully simple lines of code “if($=0,1,0)” and putting that in the ‘Transform’ field of the ConfigWizard the LED lights up when the flaps are fully retracted, as I hoped; and stays on until the flaps are extended again.
I want that LED to turn itself off once ground clearance is greater than 500’ and on again if ground clearance is less than 500’ AND the gear is extended.

Can we set the Compare for the correct result?

Kind regards & huge respect
D J Wilkinson
2019-12-28 09:51
From: ETSI, Germany
Posts: 3302
Hi Again

Now we mix up two systems :P Compare and transform normaly work with "own" value.... Means you create a result by using the Raw Value ($) that you read with that config ( Offset Adress that is used in FUIPC Tab)

When you talk about a condition that also need status from other things then we need a different system...... You like a LED that is basicly use the Flaps Offset Information ( ON if Flaps are fuly UP ) AND you like to include "altitude over ground" (below 500ft) and you also like to include "Gear Status" (down) .
THIS is now a system we need Preconditions or much more profitable "Placeholders"

You have 2 possible ways to solve this..... With PRECONDITION Tab or with PLACEHOLDERS and a special Transform field entry.

If you like you can use forum search "placeholder" for it.... Otherwise i will give you a full tutorial but now i must start working. So stay patient for a reply maby tonight.
Good Luck !
2019-12-28 10:47
From: Napier, New Zealand
Posts: 11
Hi back,
Thank you for all that information,
I have studied all of it very carefully.
I had noticed the list of references growing in the GUI but had no idea of their significance until now.

With your help I have realised how powerful and versatile Mobiflight can be.

I believe that I have implemented the concepts successfully because now I have all my LED's and annunciators doing exactly what I wanted.

Now I can go ahead and tidy up the rest of my switches and buttons.

Next major item will be mastering Encoders - but that can wait for another day.

Thanks again for all your help and patience.

Kindest regards
Respect to you.
D J Wilkinson
2019-12-29 02:09
From: ETSI, Germany
Posts: 3302
So i not need to figure out this thematic myself cause you already solved it ??? I hope so.

Whatever if you need more help simply request here.

So finaly just a important information about Precondition and placeholder logic!

Precondition is adressed to beginners and users who have absolutly no experience with formulas and programming. All is done in a grafic interface (Precondition Tab).
BUT it have one big disadvantage !
The Precondition System just "disable" a config in Mobiflight if condition turn into FALSE. ( Thats wonderfull) BUT it finaly not change the status of a output itself.

Simple Example: You read the Gear Offset and you like a LED should be OFF if Gear is UP and ON if Gear i DOWN . Additional you like to read the Master Battery Switch and the Gear LED should only light if Batteryswitch is also ON ..... So it is OFF if Battery is OFF ( Whatever Gear is Down in that case)
If you do this with Precondition then the Config itself will get disabled in the moment you set Master Battery to OFF ...... BUT if your LED is light at the moment then it will stay ON in your cockpit whatever the config is disabled now.
Thats, cause "nobody" tell the LED to swap OFF .... Mobiflight just Disable the Config but NOT the Pin Status on the Mega.

To solve this we normaly create always TWO Configs with reversed preconditions that both controll the same LED .
In this example we have a Config that read Gear and have PRecondition "Only work if Batter is ON"
And we have another Config ( on same LED) with a value of "always Zero" (Simply use transform "0" ) And This have inverted Precondition "Always work if Battery is OFF"

Then the LED is controlled All time by one of the two configs..... It get always off if the second Config is allive.... And it show GEar status if first config is working.


The Placeholder System is more comfortable and you save this double configs..... BUT you need to write a little "if-else" formula youreself.

In upper example you would use in the Gear Config a Placeholder ( Enable checkmark nearby) and use as Value the Batteryswitch Config and a Symbol like "x" for it.
In Transform line you say : if(x=1,$,0)
That means.... If "x" (The value of Placeholder Battery Switch config) is "1" (So Battery is ON) THEN show "$" ( The own value of the current config.... Gear in that case) ..... ELSE ( So if "x" is not 1) show "0" Zero .

I hope you see.... Placeholders are a bit advanced to understand but finaly more easy and faster to build.
Good Luck !
2019-12-29 08:39
From: Napier, New Zealand
Posts: 11
Greetings Pizman82
Yes, I seem to have solved it using the "Placeholder" method,
It seems fairly natural to me - once I realised what was being presented to me in the GUI.
I never would have figured it out without your help though.

Thank you for your invitation to ask questions here.

Everything seems to work with nested if(A, THEN B, ELSE C) functions. I wondered about what other logical test functions might be available for the 'Transform' on the FSUIPC Tab.
For example if(A AND B, THEN C, ELSE D) or even if(A OR B, THEN C, ELSE D). Does Mobiflight have a way of handling such things?

How do we handle sequential actions?
For example pressing the 'Annun Test' button to have all the LED's on my panel light up just for a second, then the next one has a turn and so on.
That was easily done in Link2FS with a few lines of C++ code but I don't see a simple way of doing it here. How will I do that?

D J Wilkinson
2019-12-29 10:15
From: ETSI, Germany
Posts: 3302
Hi Again.

I see your a advanced user who know what he need. :thumbup:

About Function syntax:

Here we again must split between Precondition and Placeholder.
The precondition system is a bit limmited ( to support a easy interface for beginners) but is problematic if you need advanced stuff.
You can choose multiple elements in the precondition like "A and B and C and D" ..... or .... "A or B and C" .... But it work a bit "strange"
It simply calculate each "block" of 2 Things ( with the used parameter) and then it "loop" the result to the next line.
For example "A and B or C " It now check if A and B is True and if yes THEN it take this result and Say "TRUE or C" If a/b are not both true then it would say "FALSE or C"
The strange result.... "A and B or C" occure in a error ..... "B or C and A " will work fine..... Whatever logical both are the same. Thats the problem in the logic.
You see.... This is nice for easy things like "A and B" - or- "A or B or C" ..... BUT its bad if you need deeper logics.

And HERE the Placeholder are your solution.
The syntax is more deeper as you see directly.... Parameters like AND / OR and also ELSE-IF can be used in the Transform or Compare fields.


If Value is 1 then write 77 , else if value is 2 then write 88, in all other situations write 99 ...... if($=1,77,if($=2,88,99)) (Simply start a new if(a,b,c) within the other IF )

If Value is 1 or 2 then write 88 Else write 99 ..... if($=1||$=2,88,99) ( 2 times" | "symbol German keyboard left of "y" key) is syntax for OR

If Value is bigger then 5 and less then 9 then write 88 Else write 99 ...... if($>5&$<9,88,99) ( & is the AND syntax)

You see.... You can build verry deep logics with this syntax. As i know length is not limmited directly.


About sequences.

This is a part in Mobiflight that is missing..... Maby it come in future but at the moment this not work.
You can build own code ( Lua script) to make this work.... O
Alternate is to build this by electrical setups.... Like a timer relais that is running for xx seconds after getting a impuls.
There are finaly some tricky solutions to use for example the "FSX Time in Seconds" offset. With a little formula you can build a logic that is ON/OFF in a xx second periode.
But its NOT possible to say " Do something and then wait xx seconds"
Good Luck !
2019-12-29 15:38
From: Napier, New Zealand
Posts: 11

That is more good information - thanks
Very useful to know that "||" (OR) is available.
I was surprised to see the "&" for AND but that will also be useful.

I have many other questions but I will restrain myself from asking them all at once in my excitement.
Last night I discovered that Mobiflight has a limit to the size of its data file that stores the configuration settings.
An error message came up telling me so and what I needed to do about it.
However when I had carried out the instructions nothing would work anymore.
I had to delete all my settings and rebuild it all again one step at a time.
And this time I was being very economical with the use of character spaces.
It was a great way to practice all the new things I had learned from you.

The next thing on my list is to conquer the rotary encoders.

Looking ahead though, I will need to learn how to use Mobiflight to pass data from FSX to my Lua macros and then pass the output from the macro back to FSX, all via FSUIPC.
From what you have already told me I understand that will require installation of the Lua Plugin.

Can you tell me please
a) where I find that Plugin and
b) how to install it?

Happy new year from New Zealand. We in New Zealand get there first - being 12 hours ahead of Germany. :)

[Last edited by djw4250, 2019-12-30 18:59]
D J Wilkinson
2019-12-30 18:42
From: ETSI, Germany
Posts: 3302
Hi again.

As i know the length / size of mcc files are not limited..... Or if limited the limit is verry high cause there are users here with a full B737 Cockpit.... those MCC files have hundrets of Configs.

A Limit is known in mfmc files..... the Device settings on a Mega ( In case the Mega Memory is verry small..... So the number of characters is limited for "names" )
Thats the only point i basicly know about a "Error Message".
Maby you can explane more detailed what was the problem.

To protect you of this problems for the next time i high recommend to work with a good Backup logic.
So please....
1. Save the Board Settings from every Mega to a MFMC File if you have a working setup.
So you can simply load that data to a other mega or to the same if there is a issue or it is completly broke.

2. Save after every new element (not every single Button but maby after a part like EFIS) yout MCC File.
Not overwrite the last backup..... Simply make a history. So you can easy swap back 1,2, or more steps if you spot a issue that is come in system longer time ago.
If the problem is just in the newest parts simply swap back to last backup and all is fine again.

About your questions.

The "Lua Plug In" is just called so from myself and the programmer who made it. It is no real PlugIn for Mobiflight..... its already a part of Mobiflight and implement in the main programm.

You find it for INPUT Configs..... As "Typ" you normaly choose FSUIPC Offset, EventID, PMDG Events and so on. In this Dropdown you also find LUA MACRO. Thats it !
Good Luck !
2019-12-31 01:56
From: Napier, New Zealand
Posts: 11
Thank you for that clear explanation
That all makes perfect sense now.

Yes it was as you say - the message from MFMC File where the settings are stored.
Yes I am using a Mega.
Yes I have been making 'incremental' backups.
So all is well.

Thanks for the clarification of the Lua interface.

Kind regards.
D J Wilkinson
2019-12-31 18:57