Simulation Instruments

Home›All functions›Data

Data

Simulation Instrument Studio 1

timer_start

Simulation Instrument Studio 1

Overloads

timer_start(delay)
timer_start(delay, callback)
timer_start(delay, period, callback)
timer_start(delay, period, nr_calls, callback)

Calls a function after a delay, and again on a period if you give one.

Parameters

#NameTypeDescription
1delayNumberInitial delay in milliseconds. After calling timer_start, the callback function will be executed after this delay.
2periodNumber(Optional) Time between two function calls, in milliseconds. Providing it with 'nil' will make the function only get called once.
3nr_callsNumber(Optional) Number of callbacks.
4callbackNumber(Optional, from AM/) This function will be called at every interval. Two arguments will be provided, the count and max (can be -1 if running infinitely).

Example

-- Blink the fail lamp twice a second
blink = timer_start(0, 500, function()
    fail_on = not fail_on
    visible(fail_lamp, fail_on)
end)

Example: once, and every half second

-- Once, a second after launch
timer_start(1000, function()
    log("warmup done")
end)

-- Every half second. count is how many times it has fired.
blink = timer_start(0, 500, function(count)
    visible(fail_lamp, count % 2 == 0)
end)
Photo slot: shots/timer_start.png

timer_stop

Simulation Instrument Studio 1

Overloads

timer_stop(timer_id)

Stops a timer.

Parameters

#NameTypeDescription
1timer_idNumberTimer_id received from the timer_start function.

Example

-- Sim is healthy. Stop the blink.
timer_stop(blink)
Photo slot: shots/timer_stop.png

timer_running

Simulation Instrument Studio 1

Overloads

timer_running(timer_id)

True while that timer is still scheduled.

Parameters

#NameTypeDescription
1timer_idNumberTimer_id received from the timer_start function.

Example

if timer_running(blink) then
    log("fail lamp is still blinking")
end
Photo slot: shots/timer_running.png

persist_add

Simulation Instrument Studio 1

Overloads

persist_add(key, initial_value)

A saved value. It is written next to the instrument and read on the next launch.

Parameters

#NameTypeDescription
1keyStringUnique identifier key to be able to keep different persistence objects separated.
2initial_valueObjectThe initial value of the persistence object. This value will be used when no data is yet available. This argument is optional, when not used, the data is typically initialized with all zero's.

Example

-- Declare it before the first get
persist_add("qnh", 29.92)
Photo slot: shots/persist_add.png

persist_get

Simulation Instrument Studio 1

Overloads

persist_get(persist_id)

A saved value. It is written next to the instrument and read on the next launch.

Parameters

#NameTypeDescription
1persist_idNumberPersist_id is the reference to a certain persistence object. It is received from the persist_add function.

Example

-- Last Kollsman setting, from the previous flight
qnh = persist_get("qnh") or 29.92
Photo slot: shots/persist_get.png

persist_put

Simulation Instrument Studio 1

Overloads

persist_put(persist_id, value)

A saved value. It is written next to the instrument and read on the next launch.

Parameters

#NameTypeDescription
1persist_idNumberPersist_id is the reference to a certain persistence object. It is received from the persist_add function.
2valueObjectThe value that should be written to the persistence object.

Example

persist_put("qnh", 30.12)
Photo slot: shots/persist_put.png

user_prop_add_boolean

Simulation Instrument Studio 1

Overloads

user_prop_add_boolean(name, default_value, description)

Declares a user property. Panel shows it before the instrument runs.

Parameters

#NameTypeDescription
1nameStringThe name of the user property. This name must be unique (there may only be one user property of a certain name in an instrument)
2default_valueBooleanThe default value of the property. The is the value the property gets when the user adds the instrument to a panel.
3descriptionStringA description of the property, explaining to the user what function this user property has.

Example

user_prop_add_boolean("night", false)
Photo slot: shots/user_prop_add_boolean.png

user_prop_add_enum

Simulation Instrument Studio 1

Overloads

user_prop_add_enum(name, possible_values, default_value, description)

Declares a user property. Panel shows it before the instrument runs.

Parameters

#NameTypeDescription
1nameStringThe name of the user property. This name must be unique (there may only be one user property of a certain name in an instrument)
2possible_valuesStringThe possible values of the property.
3default_valueStringThe default value of the property. The is the value the property gets when the user adds the instrument to a panel.
4descriptionStringA description of the property, explaining to the user what function this user property has.

Example

user_prop_add_enum("units", "feet", {"feet", "meters"})
Photo slot: shots/user_prop_add_enum.png

user_prop_add_hardware_id

Simulation Instrument Studio 1

Overloads

user_prop_add_hardware_id(name, default_value, description)

Declares a user property. Panel shows it before the instrument runs.

Parameters

#NameTypeDescription
1nameStringThe name of the user property. This name must be unique (there may only be one user property of a certain name in an instrument)
2default_valueStringThe default value of the property. The is the value the property gets when the user adds the instrument to a panel.
3descriptionStringA description of the property, explaining to the user what function this user property has.

Example

-- Shown in Panel before the instrument runs
user_prop_add_hardware_id("altitude_unit", "Feet")
Photo slot: shots/user_prop_add_hardware_id.png

user_prop_add_integer

Simulation Instrument Studio 1

Overloads

user_prop_add_integer(name, min, max, default_value, description)

Declares a user property. Panel shows it before the instrument runs.

Parameters

#NameTypeDescription
1nameStringThe name of the user property. This name must be unique (there may only be one user property of a certain name in an instrument)
2minNumberThe minimum value of the property.
3maxNumberThe maximum value of the property.
4default_valueNumberThe default value of the property. The is the value the property gets when the user adds the instrument to a panel.
5descriptionStringA description of the property, explaining to the user what function this user property has.

Example

user_prop_add_integer("drum_size", 28)
Photo slot: shots/user_prop_add_integer.png

user_prop_add_percentage

Simulation Instrument Studio 1

Overloads

user_prop_add_percentage(name, min, max, default_value, description)

Declares a user property. Panel shows it before the instrument runs.

Parameters

#NameTypeDescription
1nameStringThe name of the user property. This name must be unique (there may only be one user property of a certain name in an instrument)
2minNumberThe minimum value of the property. (0= 0%, 1=100%)
3maxNumberThe maximum value of the property. (0= 0%, 1=100%)
4default_valueNumberDefault percentage. (0= 0%, 1=100%)
5descriptionStringA description of the property, explaining to the user what function this user property has.

Example

-- Shown in Panel before the instrument runs
user_prop_add_percentage("altitude_unit", "Feet")
Photo slot: shots/user_prop_add_percentage.png

user_prop_add_real

Simulation Instrument Studio 1

Overloads

user_prop_add_real(name, min, max, default_value, description)

Declares a user property. Panel shows it before the instrument runs.

Parameters

#NameTypeDescription
1nameStringThe name of the user property. This name must be unique (there may only be one user property of a certain name in an instrument)
2minNumberThe minimum value of the property.
3maxNumberThe maximum value of the property.
4default_valueNumberThe default value of the property. The is the value the property gets when the user adds the instrument to a panel.
5descriptionStringA description of the property, explaining to the user what function this user property has.

Example

-- Shown in Panel before the instrument runs
user_prop_add_real("altitude_unit", "Feet")
Photo slot: shots/user_prop_add_real.png

user_prop_add_string

Simulation Instrument Studio 1

Overloads

user_prop_add_string(name, default_value, description)

Declares a user property. Panel shows it before the instrument runs.

Parameters

#NameTypeDescription
1nameStringThe name of the user property. This name must be unique (there may only be one user property of a certain name in an instrument)
2default_valueStringThe default value of the property. The is the value the property gets when the user adds the instrument to a panel.
3descriptionStringA description of the property, explaining to the user what function this user property has.

Example

user_prop_add_string("altitude_unit", "Feet")
Photo slot: shots/user_prop_add_string.png

user_prop_add_table

Simulation Instrument Studio 1

Overloads

user_prop_add_table(name, description, column_name, column_type, column_default_value, column_description, ...)

Declares a user property. Panel shows it before the instrument runs.

Parameters

#NameTypeDescription
1nameStringThe name of the user property. This name must be unique (there may only be one user property of a certain name in an instrument)
2descriptionStringA description of the property, explaining to the user what function this user property has.

Example

-- Shown in Panel before the instrument runs
user_prop_add_table("altitude_unit", "Feet")
Photo slot: shots/user_prop_add_table.png

user_prop_get

Simulation Instrument Studio 1

Overloads

user_prop_get(user_prop_id)

Returns the current value of a user property.

Parameters

#NameTypeDescription
1user_prop_idStringuser_prop_id is the reference to a certain user property. It is received from the user_prop_add_integer, user_prop_add_boolean, user_prop_add_string etc. functions.

Example

-- The pilot set this before launch
unit = user_prop_get("altitude_unit")
Photo slot: shots/user_prop_get.png

static_data_load

Simulation Instrument Studio 1

Overloads

static_data_load(path)
static_data_load(path, options)
static_data_load(path, callback)
static_data_load(path, options, callback)

Get load static data from a JSON, CSV or text file located in the resources folder.

Parameters

#NameTypeDescription
1pathStringThe location of the static file inside the resources folder (.csv, .json or *.txt).
2optionsString(Options) Extra options. See the table below for available options.
3callbackFunction(Optional) Function is called when data has been loaded. Data argument contains the data, is nil on error. The file will be read synchronously when the callback function is not provided.

Example

{
  "firstName": "John",
  "lastName": "Smith",
  "age": 27,
  "address": {
    "streetAddress": "21 2nd Street",
    "city": "New York",
    "state": "NY",
    "postalCode": "10021-3100"
  },
  "phoneNumbers": [
    "212 555-1234",
    "646 555-4567",
    "123 456-7890"
  ]
}

Example: a checklist file

-- resources/checklist.json
-- { "items": ["Flaps up", "Mixture rich", "Lights on"] }
local list = static_data_load("checklist.json")
if list then
    txt_set(item, list.items[1])
end
Photo slot: shots/static_data_load.png

sound_add

Simulation Instrument Studio 1

Overloads

sound_add(filename, volume)

A sound call. The file lives in the instrument resources.

Parameters

#NameTypeDescription
1filenameStringThis is the filename of the sound you wich to load. .wav and .mp3 files are supported.
2volumeNumber(Optional) Volume of the sound. Ranges from 0.0 (off) to 1.0 (loudest)

Example

tick = sound_add("tick.wav")
Photo slot: shots/sound_add.png

sound_loop

Simulation Instrument Studio 1

Overloads

sound_loop(sound_id)

A sound call. The file lives in the instrument resources.

Parameters

#NameTypeDescription
1sound_idNumberSound id received from the sound_add function.

Example

-- A file in the instrument resources folder
sound_loop("tick.wav")
Photo slot: shots/sound_loop.png

sound_play

Simulation Instrument Studio 1

Overloads

sound_play(sound_id)

A sound call. The file lives in the instrument resources.

Parameters

#NameTypeDescription
1sound_idNumberSound id received from the sound_add function.

Example

tick = sound_add("tick.wav")
sound_play(tick)
Photo slot: shots/sound_play.png

sound_stop

Simulation Instrument Studio 1

Overloads

sound_stop(sound_id)

A sound call. The file lives in the instrument resources.

Parameters

#NameTypeDescription
1sound_idNumberSound id received from the sound_add function.

Example

-- A file in the instrument resources folder
sound_stop("tick.wav")
Photo slot: shots/sound_stop.png

sound_volume

Simulation Instrument Studio 1

Overloads

sound_volume(sound_id, volume)

A sound call. The file lives in the instrument resources.

Parameters

#NameTypeDescription
1sound_idIDSound id received from the sound_add function.
2volumeNumberNew volume, ranges from 0.0 (off) to 1.0 (loudest)

Example

-- A file in the instrument resources folder
sound_volume("tick.wav")
Photo slot: shots/sound_volume.png

game_controller_add

Simulation Instrument Studio 1

Overloads

game_controller_add(name, callback)

Add a game controller.

Parameters

#NameTypeDescription
1nameStringGame controller name. Can be fetched from game_controller_list call.
2callbackFunctionCallback which is called when a button or axis is changed on the game controller. Three arguments will be provided in the callback. Type (0=Axis, 1=Button), index (0 based offset for multiple buttons or axis) and value.

Example

function callback(type, index, value)
    print("type = " .. type .. ", index = " .. index .. ", value = " .. tostring(value))
end

list = game_controller_list()

for k, v in pairs(list) do
    game_controller_add(v, callback)
end
Photo slot: shots/game_controller_add.png

game_controller_list

Simulation Instrument Studio 1

Overloads

game_controller_list()

List all available joysticks on the system.

Parameters

#NameTypeDescription
1game_controller_listString[]An array with all the game controllers. You can use an item in this list for the game_controller_add function.

Example

function callback(type, index, value)
    print("type = " .. type .. ", index = " .. index .. ", value = " .. tostring(value))
end

list = game_controller_list()

for k, v in pairs(list) do
    game_controller_add(v, callback)
end
Photo slot: shots/game_controller_list.png

device_add

Simulation Instrument Studio 1

Overloads

device_add(type, offset)

An external device call. Properties and commands go through the device bus.

Parameters

#NameTypeDescription
1typeStringDevice type. See the device list.
2offsetNumber(Optional) When you have multiple devices of the same type, you can provide an offset.

Example

-- External device on the device bus
id = device_add("gauge")
Photo slot: shots/device_add.png

device_command

Simulation Instrument Studio 1

Overloads

device_command(cmd_name)
device_command(device_id, cmd_name)

An external device call. Properties and commands go through the device bus.

Parameters

#NameTypeDescription
1device_idid(Optional) Device id. This can be obtained through device_add function. Not needed when starting script within Device plugin.
2cmd_nameStringCommand name which need to be set. See the device list.

Example

-- External device on the device bus
id = device_command("gauge")
Photo slot: shots/device_command.png

device_command_subscribe

Simulation Instrument Studio 1

Overloads

device_command_subscribe(cmd_name, callback)
device_command_subscribe(device_id, cmd_name, callback)

An external device call. Properties and commands go through the device bus.

Parameters

#NameTypeDescription
1device_idid(Optional) Device id. This can be obtained through device_add function. Not needed when starting script within Device plugin.
2cmd_nameStringCommand name which need to be set. See the device list.
3callbackfunctionFunction that is called when command is fired.

Example

-- External device on the device bus
id = device_command_subscribe("gauge")
Photo slot: shots/device_command_subscribe.png

device_connected

Simulation Instrument Studio 1

Overloads

device_connected()
device_connected(device_id)

An external device call. Properties and commands go through the device bus.

Parameters

#NameTypeDescription
1device_idid(Optional) Device id. This can be obtained through device_add function. Not needed when starting script within Device plugin.

Example

-- External device on the device bus
id = device_connected("gauge")
Photo slot: shots/device_connected.png

device_prop_set

Simulation Instrument Studio 1

Overloads

device_prop_set(prop_name, value)
device_prop_set(prop_name, unit, value)
device_prop_set(device_id, prop_name, value)
device_prop_set(device_id, prop_name, unit, value)

An external device call. Properties and commands go through the device bus.

Parameters

#NameTypeDescription
1device_idid(Optional) Device id. This can be obtained through device_add function. Not needed when starting script within Device plugin.
2prop_nameStringProperty name which need to be set. See the device list.
3unitStringSome properties support multiple units, e.g. needle position in percentage or absolute steps. See the device list.
4valueObjectThe value the property needs to be set. Type depends on the chosen property. See the device list.

Example

-- External device on the device bus
id = device_prop_set("gauge")
Photo slot: shots/device_prop_set.png

device_prop_subscribe

Simulation Instrument Studio 1

Overloads

device_prop_subscribe(prop_name, callback)
device_prop_subscribe(device_id, prop_name, callback)

An external device call. Properties and commands go through the device bus.

Parameters

#NameTypeDescription
1device_idid(Optional) Device id. This can be obtained through device_add function. Not needed when starting script within Device plugin.
2prop_nameStringProperty name which need to be set. See the device list.
3callbackfunctionFunction that is called when property value changes. First argument contains the data.

Example

-- External device on the device bus
id = device_prop_subscribe("gauge")
Photo slot: shots/device_prop_subscribe.png

fi_engine_cluster_add

Simulation Instrument Studio 1

Overloads

fi_engine_cluster_add(type)

A Flight Illusion gauge call. It speaks the serial protocol on the configured port.

Parameters

#NameTypeDescription
1typeStringGauge type

Example

-- Flight Illusion gauge on the serial port
id = fi_engine_cluster_add(1)
Photo slot: shots/fi_engine_cluster_add.png

fi_engine_cluster_prop_set

Simulation Instrument Studio 1

Overloads

fi_engine_cluster_prop_set(fi_gauge_id, prop_name, value)
fi_engine_cluster_prop_set(fi_gauge_id, prop_name, unit, value)

A Flight Illusion gauge call. It speaks the serial protocol on the configured port.

Parameters

#NameTypeDescription
1fi_engine_cluster_idStringReference to the Flight Illusion engine cluster
2prop_nameStringProperty name which need to be set
3unitStringSome properties support multiple units, e.g. needle position in percentage or absolute steps
4valueObjectThe value the property needs to be set. Type depends on the chosen property

Example

-- Flight Illusion gauge on the serial port
id = fi_engine_cluster_prop_set(1)
Photo slot: shots/fi_engine_cluster_prop_set.png

fi_gauge_add

Simulation Instrument Studio 1

Overloads

fi_gauge_add(address, type)

A Flight Illusion gauge call. It speaks the serial protocol on the configured port.

Parameters

#NameTypeDescription
1addressNumberUnique gauge address. Ranges from 1-255, and can be configured by Flight Illusion tools.
2typeStringGauge type

Example

-- Flight Illusion gauge on the serial port
id = fi_gauge_add(1)
Photo slot: shots/fi_gauge_add.png

fi_gauge_command

Simulation Instrument Studio 1

Overloads

fi_gauge_command(fi_gauge_id, command_name)

A Flight Illusion gauge call. It speaks the serial protocol on the configured port.

Parameters

#NameTypeDescription
1fi_gauge_idStringReference to the Flight Illusion gauge
2command_nameStringCommand name which need to be set

Example

-- Flight Illusion gauge on the serial port
id = fi_gauge_command(1)
Photo slot: shots/fi_gauge_command.png

fi_gauge_command_subscribe

Simulation Instrument Studio 1

Overloads

fi_gauge_command_subscribe(fi_gauge_id, command_name, callback_function)

A Flight Illusion gauge call. It speaks the serial protocol on the configured port.

Parameters

#NameTypeDescription
1fi_gauge_idStringReference to the flight illusion gauge
2comand_nameStringName of the command
3callback_functionFunctionThe function to call when the command is fired

Example

-- Flight Illusion gauge on the serial port
id = fi_gauge_command_subscribe(1)
Photo slot: shots/fi_gauge_command_subscribe.png

fi_gauge_prop_set

Simulation Instrument Studio 1

Overloads

fi_gauge_prop_set(fi_gauge_id, prop_name, value)
fi_gauge_prop_set(fi_gauge_id, prop_name, unit, value)

A Flight Illusion gauge call. It speaks the serial protocol on the configured port.

Parameters

#NameTypeDescription
1fi_gauge_idStringReference to the Flight Illusion gauge
2prop_nameStringProperty name which need to be set
3unitStringSome properties support multiple units, e.g. needle position in percentage or absolute steps
4valueObjectThe value the property needs to be set. Type depends on the chosen property

Example

-- Flight Illusion gauge on the serial port
id = fi_gauge_prop_set(1)
Photo slot: shots/fi_gauge_prop_set.png

fi_gauge_prop_subscribe

Simulation Instrument Studio 1

Overloads

fi_gauge_prop_subscribe(fi_gauge_id, prop_name, callback_function)

A Flight Illusion gauge call. It speaks the serial protocol on the configured port.

Parameters

#NameTypeDescription
1fi_gauge_idStringReference to the flight illusion gauge.
2prop_nameStringName of the property. See Flight Illusion gauges.
3callback_functionFunctionThe function to call when the property value is changed.

Example

-- Flight Illusion gauge on the serial port
id = fi_gauge_prop_subscribe(1)
Photo slot: shots/fi_gauge_prop_subscribe.png

interpolate_settings_from_user_prop

Simulation Instrument Studio 1

Overloads

interpolate_settings_from_user_prop(user_prop_table_value)

Create interpolate settings from a table user property.

Parameters

#NameTypeDescription
1user_prop_table_valueTableValue from a table user property. Can be obtained by calling user_prop_get on your table user property. See example below.

Example

-- Create a table with two columns
local val = user_prop_add_table("Needle calibration", "Fill table with calibration data",
                                  "Speed", "DOUBLE", 0, "Fill in the speed of the flight simulator",
                                  "Needle position", "DOUBLE", 0, "Set needle position in steps")

-- Create interpolate settings from user property
local settings = interpolate_settings_from_user_prop(user_prop_get(val))

-- Interpolate using settings made by the user
local var = interpolate_linear(settings, 25)

--Print result
print(var)
Photo slot: shots/interpolate_settings_from_user_prop.png