Home›All functions›X-Plane
X-Plane
Simulation Instrument Studio 1
xpl_dataref_subscribe
Simulation Instrument Studio 1
Definition
xpl_dataref_subscribe(dataref, type, callback_function)
Remarks
Subscribe to specified X-Plane dataref(s). Type is typically "FLOAT", "INT", "FLOAT[n]", etc.
Parameters
| Name | Description |
dataref | String. An X-Plane dataref name. Repeat dataref and type in pairs to subscribe to more than one. |
type | String. INT, FLOAT, DOUBLE, INT[n], FLOAT[n], DOUBLE[n], BYTE[n], or STRING. |
callback_function | Function. Called when new data is available. Arguments arrive in the order the datarefs were given. |
Example
From sample instrument instruments/generic_airspeed/logic.lua
xpl_dataref_subscribe("sim/cockpit2/gauges/indicators/airspeed_kts_pilot", "FLOAT", function(v)
ias = tonumber(v) or 0
redraw()
end)
xpl_dataref_subscribe("sim/cockpit2/gauges/indicators/altitude_ft_pilot", "FLOAT", function(v)
alt_ft = tonumber(v) or 0
Example: one value, and a pair
xpl_dataref_subscribe("sim/cockpit2/gauges/indicators/altitude_ft_pilot", "FLOAT", function(ft)
txt_set(alt, tostring(math.floor(ft)))
end)
-- Both arrive together, in this order
xpl_dataref_subscribe(
"sim/cockpit2/gauges/indicators/altitude_ft_pilot", "FLOAT",
"sim/cockpit2/gauges/indicators/airspeed_kts_pilot", "FLOAT",
function(ft, kts)
txt_set(alt, tostring(math.floor(ft)))
txt_set(ias, tostring(math.floor(kts)))
end)
Photo slot: shots/xpl_dataref_subscribe.png
xpl_dataref_write
Simulation Instrument Studio 1
Definition
xpl_dataref_write(dataref, type, value, offset, force)
Remarks
Write to a certain X-Plane dataref.
Parameters
| Name | Description |
dataref | X-Plane dataref name, for example sim/cockpit2/gauges/indicators/altitude_ft_pilot. |
type | Value type: FLOAT, INT, DOUBLE, or an array type such as FLOAT[8]. |
value | The value to write. |
offset | Array index to start at. 0 is the first element. |
force | True writes the dataref every frame. Set it back to false when you are done. |
Example
No sample instrument calls this yet.
xpl_dataref_write("...", "FLOAT", value, offset, force)
Photo slot: shots/xpl_dataref_write.png
xpl_command
Simulation Instrument Studio 1
Definition
xpl_command(commandref)
Remarks
Send a certain command to X-Plane.
Parameters
| Name | Description |
commandref | Simulator command name. |
Example
No sample instrument calls this yet.
xpl_command("...")
Photo slot: shots/xpl_command.png
xpl_command_subscribe
Simulation Instrument Studio 1
Definition
xpl_command_subscribe(commandref, callback_function)
Remarks
Subscribe to certain command in X-Plane.
Parameters
| Name | Description |
commandref | Simulator command name. |
callback_function | Function called when the value changes. |
Example
No sample instrument calls this yet.
xpl_command_subscribe("...", function() end)
Photo slot: shots/xpl_command_subscribe.png
xpl_connected
Simulation Instrument Studio 1
Definition
connected = xpl_connected()
Remarks
Check if we are connected to X-Plane.
Example
No sample instrument calls this yet.
xpl_connected()
Photo slot: shots/xpl_connected.png