Fs2 msg subscribe

From Sim Innovations Wiki
Jump to navigation Jump to search

Description

fs2_msg_subscribe(msg,type,...,callback_function)

fs2_msg_subscribe is used to subscribe on one or more Aerofly FS2 messages.

FS2 uses the following messages, these may be used subscribed to with this function.
The list of FS2 messages can be found here, note that this list is very limited.

Return value

This function won't return any value.

Arguments

# Argument Type Description
1 .. n msg String Reference to a message from FS2
2 .. n type String Data type of the message, can be INT,FLOAT,DOUBLE, VECTOR2D, VECTOR3D, VECTOR4d or STRING
last callback_function Function The function to call when new data is available

Example (single dataref)

-- This function will be called when new data is available from FS2
 function new_indicated_speed_callback(speed)
   print("New speed: " .. speed)
 end

 -- subscribe to FS2 message
 fs2_msg_subscribe("Aircraft.IndicatedAirspeed", "DOUBLE", new_indicated_speed_callback)

Example (multi dataref)

-- It is also possible to subscribe to multiple datarefs
 -- Note that the order in which the datarefs are given to the fs2_msg_subscribe function determines the order in which the messages will enter this function

 -- In our case 
 -- "Aircraft.Altitude" maps to "altitude"
 -- "Aircraft.IndicatedAirspeed" maps to "speed"
 function new_altitude_and_speed_callback(altitude, speed)
   print("Altitude=" .. altitude .. " Speed=" .. speed)
 end

 -- multi subscribe
 xpl_dataref_subscribe("Aircraft.Altitude",  "DOUBLE",
                       "Aircraft.IndicatedAirspeed", "DOUBLE", new_altitude_and_speed_callback)