dcs.add_observed_data()
dcs.add_observed_data(def_array)
This function register the definitions of cockpit data to be observed specified as Observed Data Definition table. It triggers the event which has specified Event ID in response to changes in the values of the registered cockpit data. The Event Value is exactly the value of the observed cockpit data.
There are three ways to specify the observed cockpit data.
-
Cockpit Control Position
By specifying theargument_number
parameter in the Observed Data Definition, you can observe elements such as switch positions, button press states, and indicator lamp statuses. The observation targets you can specify are the same as those covered by the ‘X: COCKPIT ARGUMENT IN RANGE’ trigger in the DCS Mission Editor. -
Indication Text
By specifying theindicator_id
parameter in the Observed Data Definition, you can observe the display content of indicators such as the IFEI in the F/A-18C or the DED in the F-16C. The indicators you can observe are the same as those covered by the ‘X: COCKPIT INDICATION TEXT IS EQUAL TO’ trigger in the DCS Mission Editor. -
Lua Chunk value
When you specify a Lua chunk as a string in thechunk
parameter of the Observed Data Definition, the return value of the chunk is observed. This method allows for complex behaviors, such as creating an Event Value that combines the states of multiple controls. Unless you specify afilter
to change the type of the value, the return value of the chunk must be either a string or a number.
To find the corresponding values for the argument_number
or indicator_id
parameters for cockpit instruments of each aircraft module,
refer to the 'X: COCKPIT ARGUMENT IN RANGE' trigger and the 'X: COCKPIT INDICATION TEXT IS EQUAL TO' trigger sections in the DCS User Manual.
Parameters
Parameter | Type | Description |
---|---|---|
def_array | table | This parameter specifies the data to be observed as an array of Observed Data Definition. |
Observed Data Definition
Key | Type | Description |
---|---|---|
event | number | Event ID for the event triggered when the observed data changes |
argument_number | number | The ID number of the cockpit argument to be observed. You must specify only one of the following parameters, argument_number , indicator_id , or chunk . |
indicator_id | number | The ID value of the cockpit indicator to be observed. You must specify only one of the following parameters, argument_number , indicator_id , or chunk . |
chunk | string | A string representing the Lua chunk that returns the value to be observed. You must specify only one of the following parameters, argument_number , indicator_id , or chunk . |
filter | table string | This parameter is used to specify the conditions that trigger an event, either by limiting it to when the observed data matches a specific value or by transforming the value. If an array table is provided, the event is triggered when the observed value changes to one of the values in the table. If a string representing a Lua chunk is specified, the chunk is called every frame in DCS World, with the observed value passed as an argument. The return value of the chunk becomes the Event Value. However, if the chunk does not return a value, or if the return value’s type is not a string or number, the event will not be triggered. This parameter is optional. |
epsilon | number | If the change in the value of the observed data after passing through the filter does not exceed this value, no event will be triggered. Choosing an appropriate value helps prevent unnecessary event generation, reducing system load. This specification is ignored if the value type of the observed data is not a number. This parameter is optional. The default is 0 |
Return Values
This function doesn't return any value.