Simulation Instruments

Home›All functions›Helpers

Helpers

Simulation Instrument Studio 1

event_subscribe

Simulation Instrument Studio 1

Overloads

event_subscribe(callback)

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

Parameters

#NameTypeDescription
1callbackFunctionFunction that should be called on an event.

Example

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

event_subscribe(event_callback)

Example: the sim changed

event_subscribe(function(event)
    if event == "FLIGHT_SIM_CHANGED" then
        visible(flag, not xpl_connected())
    end
end)
Photo slot: shots/event_subscribe.png

geo_rotate_coordinates

Simulation Instrument Studio 1

Overloads

geo_rotate_coordinates(degrees, radius_x, radius_y)

Get the x and y coordinates from a circle with a certain radius and angle.

Parameters

#NameTypeDescription
1degreesNumberThe number of degrees to calculate with.
2radius xNumberThe x radius in pixels. This is the number of pixels from the center of the circle to the horizontal edge.
3radius yNumberThis value is optional. The y radius in pixels. This is the number of pixels from the center of the circle to the vertical edge.

Example

-- Calculate the x and y coordinate on 45 degrees with a radius of 200 pixels
face = img_add("face.png", 100, 100, 200, 200)

x, y = geo_rotate_coordinates(45,200)

move(face, x, y, nil, nil)

-- Calculate the x and y coordinate (oval) on 45 degrees with a radius x of 200 pixels and radius y of 100 pixels
myimage2 = img_add("face.png", 100, 100, 200, 200)

x, y = geo_rotate_coordinates(45,200,100)

move(myimage2, x, y, nil, nil)
Photo slot: shots/geo_rotate_coordinates.png

has_feature

Simulation Instrument Studio 1

Overloads

has_feature(name)

Has_feature can be used to check if the current version of Studio or Studio supports the asked feature.

Parameters

#NameTypeDescription
1nameStringThe feature name.

Example

if has_feature("TIMER") then
  timer_start(0, 100, function()
    print("timer callback")
  end)
end
Photo slot: shots/has_feature.png

instrument_prop

Simulation Instrument Studio 1

Overloads

instrument_prop(property)

Returns a value from info.xml. Width and height are the instrument size, not the panel size.

Parameters

#NameTypeDescription
1propertyStringThe type of property to fetch. See the table below

Properties

PropertyTypeDescription
AIRCRAFTStringAircraft the instrument is set for.
AUTHORStringAuthor.
TYPEStringInstrument type.
UUIDStringInstrument id.
PREF_WIDTHNumberPreferred width, from info.xml.
PREF_HEIGHTNumberPreferred height, from info.xml.
WIDTHNumberWidth in use.
HEIGHTNumberHeight in use.
DESCRIPTIONStringDescription.
VERSIONNumberInstrument version.
DEVELOPMENTBooleanTrue when launched from the editor.
PLATFORMStringWINDOWS, MAC, LINUX, RASPBERRY_PI, or UNKNOWN.

Example

-- Preferred size from info.xml. Do not use the panel size.
w = instrument_prop("PREF_WIDTH")
h = instrument_prop("PREF_HEIGHT")
Photo slot: shots/instrument_prop.png

interpolate_linear

Simulation Instrument Studio 1

Overloads

interpolate_linear(settings, value)
interpolate_linear(settings, value, cap)

Interpolate a value with given settings.

Parameters

#NameTypeDescription
1settingsTableInterpolate settings. Can be manually created (see example), or created from table user property with interpolate_settings_from_user_prop function. Make sure all settings are provided in ascending order.
2valueNumberInput value.
3capBoolean(Optional, default false) When input range is outside of settings and cap is false, nil is returned. Otherwise the min or max output value is returned.

Example

-- 0 kt is 0 degrees, 200 kt is 300 degrees
deg = interpolate_linear(ias, {0, 0}, {200, 300})

Example: a table, and a pilot table

-- 0 kt is 0 degrees, 100 kt is 140, 200 kt is 300
local curve = { {0, 0}, {100, 140}, {200, 300} }
local deg = interpolate_linear(curve, 150)

-- Same curve, filled in by the pilot before launch
local prop = user_prop_add_table("Airspeed curve", "Knots against needle degrees", "Knots", "DOUBLE", 0, "Indicated", "Degrees", "DOUBLE", 0, "Needle")
local from_pilot = interpolate_settings_from_user_prop(user_prop_get(prop))
local deg2 = interpolate_linear(from_pilot, 150)
Photo slot: shots/interpolate_linear.png

log

Simulation Instrument Studio 1

Overloads

log(message, ...)
log(type, message, ...)

Writes a line to the Studio log.

Parameters

#NameTypeDescription
1typeString(Optional) Can be 'INFO', 'WARN' or 'ERROR'. Default is set to be an info message.

Example

log("altitude " .. alt_ft)
Photo slot: shots/log.png

panel_prop

Simulation Instrument Studio 1

Overloads

panel_prop(property)

Get the settings from the current panel.

Parameters

#NameTypeDescription
1propertyStringThe type of property to fetch. See the table below

Properties

PropertyTypeDescription
AUTHORStringPanel author.
NAMEStringPanel name.
UUIDStringPanel id.
LAYOUT_UUIDStringLayout id.
WIDTHNumberPanel width.
HEIGHTNumberPanel height.
DESCRIPTIONStringDescription.
VERSIONNumberPanel version.
DEVELOPMENTBooleanTrue when launched from the editor.
PLATFORMStringWINDOWS, MAC, LINUX, RASPBERRY_PI, or UNKNOWN.

Example

-- Print the panel author
print( panel_prop("AUTHOR") )

-- See if we started from the create/edit tab
if panel_prop("DEVELOPMENT") then
  print("We are running in development mode!")
end
Photo slot: shots/panel_prop.png

resource_info

Simulation Instrument Studio 1

Overloads

resource_info(filename)

Resource_info can be used to get information of a resource file. This can also be used to check if a resource exists.

Parameters

#NameTypeDescription
1filenameStringThe file name of the resource. Including it's extension.

Example

-- We are looking for more information about the bla.png image
resource_meta = resource_info("bla.png")

-- Check if the image could be found
if resource_meta == nil then
  print("bla.png not found!")
elseif resource_meta["TYPE"] == "IMAGE" then
  print("bla.png is an image and has w=" .. resource_meta["WIDTH"] .. " h=" .. resource_meta["HEIGHT"])
else
  print("bla.png is not an image!")
end
Photo slot: shots/resource_info.png

shut_down

Simulation Instrument Studio 1

Overloads

shut_down(type)

Shut down the application (Studio or Studio) or the system where the instrument runs on.

Parameters

#NameTypeDescription
1typeString'APPLICATION' if you want to shut down Studio or Studio, or 'SYSTEM' if you want to shutdown the system (windows, Raspberry Pi etc.)

Example

-- Shut down Windows or the Raspberry Pi
shut_down("SYSTEM")
Photo slot: shots/shut_down.png

var_cap

Simulation Instrument Studio 1

Overloads

var_cap(value,min,max)

Limit a value to a given minimum and maximum value.

Parameters

#NameTypeDescription
1valueNumberThe is the value that needs to be limited to the min and max value.
2minNumberThe minimum value to limit to.
3maxNumberThe maximum value to limit to.

Example

-- Keep the needle on the card
deg = var_cap(deg, 0, 360)
Photo slot: shots/var_cap.png

var_format

Simulation Instrument Studio 1

Overloads

var_format(value,decimals)

Round a number to a certain number of decimals and always shows that selected amount of decimals.

Parameters

#NameTypeDescription
1valueNumberThe is the value that needs to be rounded.
2decimalsNumberThe number of decimals the value should get.

Example

txt_set(alt, var_format(alt_ft, 0))
Photo slot: shots/var_format.png

var_round

Simulation Instrument Studio 1

Overloads

var_round(value,decimals)

Round a number to a certain number of decimals.

Parameters

#NameTypeDescription
1valueNumberThe is the value that needs to be rounded
2decimalsNumberThe number of decimals the value should get.

Example

alt_txt = var_round(alt_ft, 10)
Photo slot: shots/var_round.png

variable_subscribe

Simulation Instrument Studio 1

Overloads

variable_subscribe(source,variable_name,type,...,callback_function)

Subscribe to more different data sources, such as X-Plane, FSX and SI variables.

Example

-- Note that the order in which the variables are given to the variable_subscribe function determines the order in which the variables will enter this function

-- In our case 
-- "sim/cockpit2/gauges/indicators/altitude_ft_pilot" maps to "altitude"
-- "TIME ZULU" maps to "time_seconds"
-- "MY_CUSTOM_VARIABLE" maps to "my_custom_variable"
function callback_function(altitude, time_seconds, my_custom_variable)
  print("Altitude from X-Plane=" .. altitude)
  print("Time seconds from FSX=" .. time_seconds)
  print("My Custom variable from SI=" .. my_custom_variable)
end

-- multi subscribe
variable_subscribe("XPLANE", "sim/cockpit2/gauges/indicators/altitude_ft_pilot",  "FLOAT",
                   "FSX", "TIME ZULU", "Seconds",
                   "SI", "MY_CUSTOM_VARIABLE", "INT", callback_function)
Photo slot: shots/variable_subscribe.png

request_callback

Simulation Instrument Studio 1

Overloads

request_callback(callback_function)

Force a callback on a given data subscription (X-Plane, FSX, FS2, FS2020, IIC or external sources).

Parameters

#NameTypeDescription
1function_callbackStringThe callback function that should be updated

Example

-- This function will be called when new data is available from X-Plane
  function new_altitude_callback(altitude)
    print("New altitude: " .. altitude)
  end

  -- Subscribe X-Plane datarefs
  xpl_dataref_subscribe("sim/cockpit2/gauges/indicators/altitude_ft_pilot", "FLOAT", new_altitude_callback)

  -- Force a callback. The 'new_altitude_callback' function will be called here with its current arguments.
  request_callback(new_altitude_callback)
Photo slot: shots/request_callback.png