Event subscribe

From Sim Innovations Wiki
Jump to navigation Jump to search

Description

event_subscribe(callback)

event_subscribe is used to subscribe to global events. E.g., when the instrument or panel is starting, showing or closing.

Return value

This function won't return any value.

Arguments

# Argument Type Description
1 callback Function Function that should be called on an event.

Event types

# Event Type Description
1 STARTED String This event is called after the initial execution of the instrument or panel lua functions.
2 SHOWING String This event is called when the instrument or panel is being shown. This will be called when the splash screen is removed.
3 CLOSING String This event is called when the instrument or panel is closing.
4 FLIGHT_SIM_CHANGED String This event is called when flight simulator has changed.

Example (Generic)

function event_callback(event)
  print("Received event: " .. event)
end

event_subscribe(event_callback)

Example (Flight simulator connection)

function event_callback(event)
    if event == "FLIGHT_SIM_CHANGED" then
        if xpl_connected() then
            print("We are connected to X-plane")
        else
            print("We are not connected to X-plane")
        end
    end
end

event_subscribe(event_callback)