coreDS™ X-Plane – Lua scripting samples

Overview

The Lua scripting engine uses two main Objects to interaction with the simulation and/or the simulator framework.

DSimLocal defines the current property to which the script is assigned. This can be a PDU, and Interaction or and Object. The script can also be assigned to a property.

DSimWorld defines the global representation of the simulation, as seen by Lua and includes all the Objects and their current values.

Examples

Calculate a value from X-Plane internal properties and set it in a HLA attribute

See the code
function func ()
 if (DSimWorld ~= nil) and (DSimWorld.Aircraft1 ~= nil) then
 DSimLocal.Value= tostring(math.sqrt(DSimWorld.Aircraft1.local_ax*DSimWorld.Aircraft1.local_ax + DSimWorld.Aircraft1.local_ay*DSimWorld.Aircraft1.local_ay+ DSimWorld.Aircraft1.local_az*DSimWorld.Aircraft1.local_az) / 9.8)
 end
end

Overwrite values received from the Simulator with static values. This is an example of how the Lua scripting engine can be used to manipulate data before sending them back to the simulation framework.

See the code
function func ()
    DSimLocal.DeadReckoningAlgorithm_A_Alternatives.WorldLocation.X = "150"
    DSimLocal.DeadReckoningAlgorithm_A_Alternatives.WorldLocation.Y = "150"
    DSimLocal.DeadReckoningAlgorithm_A_Alternatives.WorldLocation.Z = "150"

    DSimLocal.DeadReckoningAlgorithm_A_Alternatives.DeadReckoningAlgorithm = "2"
end