Calls a function after a delay, and again on a period if you give one.
Parameters
#
Name
Type
Description
1
delay
Number
Initial delay in milliseconds. After calling timer_start, the callback function will be executed after this delay.
2
period
Number
(Optional) Time between two function calls, in milliseconds. Providing it with 'nil' will make the function only get called once.
3
nr_calls
Number
(Optional) Number of callbacks.
4
callback
Number
(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 launchtimer_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
#
Name
Type
Description
1
timer_id
Number
Timer_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
#
Name
Type
Description
1
timer_id
Number
Timer_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
#
Name
Type
Description
1
key
String
Unique identifier key to be able to keep different persistence objects separated.
2
initial_value
Object
The 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 getpersist_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
#
Name
Type
Description
1
persist_id
Number
Persist_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
#
Name
Type
Description
1
persist_id
Number
Persist_id is the reference to a certain persistence object. It is received from the persist_add function.
2
value
Object
The value that should be written to the persistence object.
Declares a user property. Panel shows it before the instrument runs.
Parameters
#
Name
Type
Description
1
name
String
The name of the user property. This name must be unique (there may only be one user property of a certain name in an instrument)
2
description
String
A description of the property, explaining to the user what function this user property has.
Example
-- Shown in Panel before the instrument runsuser_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
#
Name
Type
Description
1
user_prop_id
String
user_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")
Get load static data from a JSON, CSV or text file located in the resources folder.
Parameters
#
Name
Type
Description
1
path
String
The location of the static file inside the resources folder (.csv, .json or *.txt).
2
options
String
(Options) Extra options. See the table below for available options.
3
callback
Function
(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.
-- 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
#
Name
Type
Description
1
filename
String
This is the filename of the sound you wich to load. .wav and .mp3 files are supported.
2
volume
Number
(Optional) Volume of the sound. Ranges from 0.0 (off) to 1.0 (loudest)
A sound call. The file lives in the instrument resources.
Parameters
#
Name
Type
Description
1
sound_id
Number
Sound id received from the sound_add function.
Example
-- A file in the instrument resources foldersound_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
#
Name
Type
Description
1
sound_id
ID
Sound id received from the sound_add function.
2
volume
Number
New volume, ranges from 0.0 (off) to 1.0 (loudest)
Example
-- A file in the instrument resources foldersound_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
#
Name
Type
Description
1
name
String
Game controller name. Can be fetched from game_controller_list call.
2
callback
Function
Callback 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
#
Name
Type
Description
1
game_controller_list
String[]
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
Create interpolate settings from a table user property.
Parameters
#
Name
Type
Description
1
user_prop_table_value
Table
Value 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 resultprint(var)