Simulation Instruments

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

NameDescription
datarefString. An X-Plane dataref name. Repeat dataref and type in pairs to subscribe to more than one.
typeString. INT, FLOAT, DOUBLE, INT[n], FLOAT[n], DOUBLE[n], BYTE[n], or STRING.
callback_functionFunction. 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

NameDescription
datarefX-Plane dataref name, for example sim/cockpit2/gauges/indicators/altitude_ft_pilot.
typeValue type: FLOAT, INT, DOUBLE, or an array type such as FLOAT[8].
valueThe value to write.
offsetArray index to start at. 0 is the first element.
forceTrue 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

NameDescription
commandrefSimulator 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

NameDescription
commandrefSimulator command name.
callback_functionFunction 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