Xplane interface
Posted: 14 Jun 2015, 21:33
Installation
LuaMacros can control Xplane as my main motivation is flight simulation. You need to install Xplane plugin to get interface to work. Xplane plugin is currently provided only for Windows platform 64bit version. LuaMacros is windows specific program so there's no sense to provide plugin for other platforms. I believe most of windows users fly with 64bit version so I haven't compiled 32bit version. Installation is easy, in Xplane home go to Resources/plugins directory, create luamacros\64 directories and copy win.xpl to 64 directory. Standard thing, no big deal.
Then you can use Xplane related commands in LuaMacros.
Commands
With lmc_xpl_command you just execute command in xplane. List of available commands can be found in Xplane's Resources\plugin directory in file Commands.txt.
Some commands can be "started" and "finished" - typically when you need to hold some button like starter. Then you use separate command for start and end
Text
You can display text in Xplane e.g. to indicate that some actions were executed, mode has changed etc. Then you can call command
It has 1 mandatory parameter and 2 optional
Variables are called datarefs in Xplane (SDK). Available datarefs are listed in Xplane's Resources\plugin directory in file DataRefs.txt. Datarefs can be read and some of them (see txt) can be written to. To read dataref use command
The only argument is dataref's name and value is returned as a result of function call. So you would actually use at least something like
When you need to write to a dataref add one more parameter (with value) and call
Some datarefs are arrays (e.g. engine related) so then you use one more argument to indicate array index (0 is the first element)
Your script can be informed when value of some variable in Xplane has changed. In this case you use function lmc_on_xpl_var_change providing variable name and callback function. For example you can be informed when another plane is loaded by
However some values (like current latitude or longitude) change so often that your script would be overloaded with calls that you don't ever need (new variable value is checked with each simulation frame). So you can add one more parameter with number of milliseconds between each callback - even if variable has changed more times.
Also the callback function can take one more argument with number of changes of the variable from last callback. It means if you don't use this "ignore interval in ms" the second argument of callback function will be always 1.
The on-change callback can be also unregistered with function
Callback for array datarefs is not (yet?) implemented.
Please note the Xplane interface hasn't been tested much. Report any bugs in this forum. Thanks.
LuaMacros can control Xplane as my main motivation is flight simulation. You need to install Xplane plugin to get interface to work. Xplane plugin is currently provided only for Windows platform 64bit version. LuaMacros is windows specific program so there's no sense to provide plugin for other platforms. I believe most of windows users fly with 64bit version so I haven't compiled 32bit version. Installation is easy, in Xplane home go to Resources/plugins directory, create luamacros\64 directories and copy win.xpl to 64 directory. Standard thing, no big deal.
Then you can use Xplane related commands in LuaMacros.
Commands
Code: Select all
lmc_xpl_command('sim/view/still_spot')
Some commands can be "started" and "finished" - typically when you need to hold some button like starter. Then you use separate command for start and end
Code: Select all
lmc_xpl_command_begin('sim/engines/engage_starters')
lmc_xpl_command_end('sim/engines/engage_starters')
You can display text in Xplane e.g. to indicate that some actions were executed, mode has changed etc. Then you can call command
Code: Select all
lmc_xpl_text('From LUA macros')
lmc_xpl_text('From LUA macros', 0.5)
lmc_xpl_text('From LUA macros', 0.7, 10)
- (mandatory) text to be shown
- (optional) y-position as float, 0 is top left corner, 1 is bottom left corner. Default is 0.3
- (optional) timeout in seconds, after this timeout text disappears. With 0 timeout text will stay on the screen
Variables are called datarefs in Xplane (SDK). Available datarefs are listed in Xplane's Resources\plugin directory in file DataRefs.txt. Datarefs can be read and some of them (see txt) can be written to. To read dataref use command
Code: Select all
lmc_get_xpl_variable('sim/cockpit2/radios/actuators/adf1_frequency_hz')
Code: Select all
print(lmc_get_xpl_variable('sim/cockpit2/radios/actuators/adf1_frequency_hz'))
Code: Select all
lmc_set_xpl_variable('sim/cockpit2/radios/actuators/adf1_frequency_hz', 425)
Code: Select all
print(lmc_get_xpl_variable('sim/flightmodel/engine/ENGN_thro', 0)) -- throttle of first engine
lmc_set_xpl_variable('sim/flightmodel/engine/ENGN_thro', 0.3, 1) -- set throttle of second engine
Code: Select all
lmc_on_xpl_var_change('sim/aircraft/view/acf_tailnum', function(value)
print('Have new plane ' .. value)
end)
Code: Select all
varName='sim/cockpit2/radios/actuators/adf1_frequency_hz'
lmc_on_xpl_var_change(varName,
function(value, count)
print(varName .. ' changed to ' .. value .. ' with ' .. count .. ' changes')
end, 1000)
The on-change callback can be also unregistered with function
Code: Select all
lmc_remove_xpl_var_change('sim/cockpit2/radios/actuators/adf1_frequency_hz')
Please note the Xplane interface hasn't been tested much. Report any bugs in this forum. Thanks.