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! 

05/03/2024 - This forum is read-only

The community support for MobiFlight has moved exclusively over to our Discord server. Register for free and enjoy more interactive functions like image and video upload, voice chat. More than 7,000 registered users around the world make it a great experience!

See you on our MobiFlight Community Discord server.

A HUGE Thank You to everyone who participated in the forum, especially obviously to Pizman and Stephan who did an outstanding job over so many years providing an incredible service to the MobiFlight community.

The forum is still providing a lot of good content, hence we keep this information accessible.

icon
Avatar
Ryan27679
Posts: 52
Okay, I apologise profusely to everyone before I start this post.

I got myself the A2A C-172, so now I have to figure out how to use LVARS..

I've looked through the forum but I still have questions.

function Lights_Taxi(offset, value) --- does 'offset, value' remain as such or do I need to define these?
if (value == 1) then ipc.writeLvar("OHD_EXT_LIGHTS_L_TAXI_SW", 1) --- why '==' and not just '='
else ipc.writeLvar("OHD_EXT_LIGHTS_L_TAXI_SW", 0) --- ipc.writeLvar - are there different commands or is this the only one I'm likely to need?
end
end --- why 2 'end's for the function? Does the if/then/else require its own 'end'?

function Lights_Landing(offset, value)
if (value == 1) then
ipc.writeLvar("OHD_EXT_LIGHTS_L_FLARE_SW", 1)
ipc.writeLvar("OHD_EXT_LIGHTS_L_APPR_SW", 1)
else ipc.writeLvar("OHD_EXT_LIGHTS_L_FLARE_SW", 0)
ipc.writeLvar("OHD_EXT_LIGHTS_L_APPR_SW", 0)
end
end

event.offset("66C0","UB","Lights_Taxi") --- Do I set my switch or button to change the value of these offsets as normal? I believe 'UB' defines the type and size of the variable.
event.offset("66C2","UB","Lights_Landing")

During the if/then/else part, is there any way of using more than one condition? Such as 'and/or if' or something to that effect?
What I mean is, I use switches for 2 mags and starter. The A2A LVAR has a 'key' like the 172 usually does, and its position is represented as a percentage, so each switch has to add to this number until when I push the momentary starter switch the value needs to be 100 or just under. So I need to add up the values of each switch, something like $=x+y+z..

It's maybe asking too much and it's probably too complex a place to start. Just understanding the basic formula above will keep me busy for now.

I appreciate any advice.
2018-10-15 09:45
Avatar
pizman82
Moderator
From: ETSI, Germany
Posts: 6010
Supporter
Hi
I think here is the wrong place for this. (maby)

For your basic questions i recomend to google for "LUA Tutorial" or "Learning programming with LUA"

There you get a lot of information.... For example in "C" Programming language and also LUA there is a sigenficant difference between = and ==.

Same with your END Question.... You must see the whole Script... Not only a Part.... Maby the End is still from a other segement.
Here i recommend to you to use a good tool. Not open those scripts with a standard editor like WindowsEditor..... Use a programmer tool like "Note++"
Its freeware ! there you can see verry easy what end is for what function cause every part is seperated with tabulator steps.
Also Commands are mostly in a different color. Verry cool if you startupwith scripting !

About the commands.... ipc.write is just the writing command..... so ipc.read is the reading command. And there are many many more you should know to work with it.
UB normaly mean UnsignetByte ....So its a 1 Byte (8 Bit) Unsignet Offset !

Finaly... LUA is based on C.... So multiple conditions are possible.... IF, ELSEIF, ELSE .... And pretty sure AND,NOT,OR and so on.
About the syntax of those advanced Functions you also need to check out the guides !


****
About the last thing with your Key.... You should explore the Offset or better the LVAR in that case.... Then we can thik about a good logic to work with !
Good Luck !
2018-10-15 14:32
Avatar
Ryan27679
Posts: 52
Many thanks Pizman for your advice as always. The last time I programmed anything was in BASIC on a BBC microcomputer back in the late 1980s I think... 5.25" floppy discs, when floppy discs were still actually floppy...

I'll check out the program and tutorials you advised and see what I can pick up :)

Looks like it will be a much longer-term project than I'd hoped!
2018-10-15 16:01
Avatar
Ryan27679
Posts: 52
Okay, so I have my starter switch assigned to 0x66CA, which works.

Problem is now assigning it to the script, as well as writing it at all!

function Starter_switch(66CA, 0)
if (value == 1) then ipc.writeLvar("L:Magnetos1Pct", 100)
else ipc.writeLvar("L:Magnetos1Pct", 0)
end
end

event.offset("66CA","UB","Starter_switch")

The above is bound to be wrong, but it's where I'm starting until I understand things. I'm ignoring the mags just now, only want to make the prop turn!
A2A's LVAR is (L:Magnetos1Pct,percent) and any value from 86-100 should have the key in the 'starter' position.

FSUIPC is logging the 66CA value switching from 0 to 1 and back, I have CTRL-SHIFT-S set to run the LUA script but the log shows "B:\Prepar3D v4\Modules\ACAC172.lua": killed... That probably isn't helping either..
2018-10-15 20:18
Avatar
pizman82
Moderator
From: ETSI, Germany
Posts: 6010
Supporter
Is this the complete script you try to run ?

I´m also not a programmer and my skills here are poor.... But at first i miss the "loop"
This script must be active at all time.... With only this part it will run 1 time and then stop... right ?
Good Luck !
2018-10-15 21:17
Avatar
Ryan27679
Posts: 52
Thats just copied from the tutorial elsewhere so it may well be incomplete.

I tried to find working examples to modify but have had surprisingly little luck!

I'll keep trying!
2018-10-16 09:35
icon