# Creating WASM Systems {{< glossterm >}}wasm{{< /glossterm >}} (C/C++) systems can be developed for Microsoft Flight Simulator 2024 with the **Microsoft Flight Simulator Platform Toolset.** System modules are important as they can be used for important tasks that do not require anything to be drawn to the screen, for example: - computational processes that do not need to be rendered, like physics. - centralised computation of data needed by other gauges in the same module.   These types of module have "init", "update" and "kill" callbacks, but *no* draw, and you can find an example aircraft showing off system modules here: - [GaugeAndSystemsAircraft](../../samples-tutorials/samples/simobjects-aircraft/modularaircraft/gaugeandsystemsaircraft/)     ### Creating A New System For Your Project As explained in the [Creating & configure WASM Project](creating-a-wasm-project/), you first need to create a MSFS 2024 WASM Module. By doing that, you will get a new project with only the `module_init` and `module_deinit` functions.   To create a new system, right click on your project in the solution explorer and add a new file. In the selection page, choose MSFS and pick **System**.   After selecting the **MSFS WASM Module** template, you will be presented with the following basic project, in which you'll be editing: ``` wasm MSFS_CALLBACK bool [MODULE_NAME]_system_init(FsContext ctx, sSystemInstallData* pInstallData) { // This is called during initialization of the system // do initialization // ... // return false if there is any error return true; } ``` The `[MODULE_NAME]_system_init` is the initialisation function - the first function to be called in the system cycle - that allows you to initialise everything related to the system. - The context referencing the system is given using the `ctx` parameter, and must be unique. - The `pInstallData` parameter points to a `sSystemInstallData` structure. This structure is found in `MSFS_SystemContext.h`, and looks like this: ``` wasm struct sSystemInstallData { char *parameterString; // contains String Parameter given in the systems.cfg } ``` - The `parameterString` member of the `sSystemInstallData` struct is filled from the data given in the `[WASM_SYSTEM.N]` section of the `systems.cfg`.   ``` wasm MSFS_CALLBACK bool [MODULE_NAME]_system_update(FsContext ctx, float dTime) { // This is called each frame // dTime is the time between the previous frame and this one // return false if there is any error return true; } ``` The `[MODULE_NAME]_system_update` is the update function dedicated to this gauge. It will be called once per frame. This function must not be used for draw functions because it will be called at a moment in which the draw system in not ready. - The context referencing the system is given using the `ctx` parameter, and must be unique (this is the same as that which is used in the `init` function). - The `dTime` parameter represents the time between the previous update and this one. Note that the callback must return `true` if the initialisation hasn't encountered any errors.   ``` wasm MSFS_CALLBACK bool System_system_kill(FsContext ctx) { // This is called before the system is destroyed // return false if there is any error return true; } ``` The `[MODULE_NAME]_system_kill` is the de-initialisation function - the last function to be called in the system cycle when the system is killed - and it allows you free associated data, and close connections (with SimConnect for example). - The context referencing the system is given using the `ctx` parameter, and must be unique (this is the same as that which is used in the `init` function).     ### Editing The WASM Module Project Now you've initialised the new WASM project and setup Visual Studio, you'll need to edit the source code to include the minimum header files - supplied by the SDK - to create the module. You can find all the available files that can be included from the following SDK location: ``` codeblock \MSFS SDK\WASM\include\MSFS ``` {{< image-center src="images/6_Programming/WASM/wasm_tutorial//msfs_h_location.png" alt="Location Of The MSFS.h File" >}}   These different API's are as follows:     ### WebAssembly System Module Constraints When creating your {{< glossterm >}}wasm{{< /glossterm >}} systems, there are a few things to be taken into consideration: - The {{< glossterm >}}wasm{{< /glossterm >}} module must be in the `wasm` folder or the `panels` folder. - The {{< glossterm >}}wasm{{< /glossterm >}} module must be in the same package as the `systems.cfg`. - The {{< glossterm >}}wasm{{< /glossterm >}} module must be in a SimObject or a SimAttachment. - Module path length is 511 char at max. - System name length is 63 char at max. - String parameter length is 1023 char at max.     ### Adding The System To Your Aircraft Once you have created the gauge, you need to be able to add it to your aircraft and to test it. This means that you should already have created an aircraft package (as explained here: [Creating The Project](../../samples-tutorials/tutorials/aircraft-checklist/creating-the-project/)), and after building the {{< glossterm >}}wasm{{< /glossterm >}} module from Visual Studio, you will want to save in the `wasm` file in the **PackageSources** directory.   Once you have built the module and saved it to the appropriate location, you need to tell the aircraft to reference it. This is done in the [`systems.cfg`](../../content-configuration/cfg-files/systems.cfg/), under the `[WASM_SYSTEM.N]` header, something like this: ``` wasm [WASM_SYSTEM.0] ModulePath=/ SystemName= ParameterString="blah" ``` A more complete example would look like this: ``` wasm [WASM_SYSTEM.0] ModulePath=SimObjects/Airplane/MyCompanyWasm_Aircraft/common/wasm/myModule.wasm SystemName=mySystem ParameterString=AircraftVariationName, 1 [WASM_SYSTEM.1] ModulePath=SimObjects/Airplane/MyCompanyWasm_Aircraft/common/wasm/myModule.wasm SystemName=mySecondSystem [WASM_SYSTEM.2] ModulePath=SimObjects/Airplane/MyCompanyWasm_Aircraft/presets/mycompany/presetName/wasm/myModuleInPreset.wasm SystemName=presetSystem ```   The important thing to note here is that a `system.cfg` file can **only reference a WASM module that is in the same package**. If a WASM system is meant to be shared between multiple packages, then it should be configured as a [Sim Attachment](../../content-configuration/modular-simobjects/simattachments/sim-attachment-libraries/). It should also be noted that the WASM file - located in WASM folder - can also contain [WASM Gauges,](creating-wasm-gauges/) if required.   When you have the saved the file in the correct location, you can go ahead and build the package (as explained here: [Building A Package](../../devmode/editors/project-editor/the-project-editor/#building-a-package)). Once built, you will need to restart the flight to see the module in the simulation. Note that this is the case for every edition you make to the WASM code - afterwards it will need to be re-exported, built, and the flight restarted.