Visual Studio Code
In order to debug using Visual Studio code, you need to install the lrdb-beamng extension: https://marketplace.visualstudio.com/items?itemName=beamng.lrdb-beamng
With the extension installed, make sure to start the game with -moddev
and keep it running.
To attach the debugger, switch to the 'Run and Debug' tab in Visual Studio Code (menu 'View' -> 'Run' or by pressing CTRL + SHIFT + D
). Click on the "create a launch.json" link and replace the content with the following:
{
"version": "0.2.0",
"configurations": [
{
"type": "lrdb",
"request": "attach",
"name": "Attach",
"host": "localhost",
"port": 21110,
"sourceRoot": "C:/Program Files (x86)/Steam/steamapps/common/Desynced/Desynced/Content/mods",
"stopOnEntry": false,
}
]
}
Make sure that the "sourceRoot" field matches your Desynced installation, it always needs to point to the top "mods" directory and not a specific mod directory inside of it. Also make sure to use forward slashes / as path separator. With the launch configuration saved, press F5 to attach the debugger to the game. If it doesn't end up connecting, open the "LUA REMOTE DEBUGGER - VMS" panel in the 'Run and Debug' tab of Visual Studio Code and try to double click the Desynced Lua VM which should be shown running on "localhost:21110".
Once connected, you'll have full access to breakpoints, code stepping, as well as accessing local and global variables and the watch window. Also it is recommended to open the Debug Console (menu 'View' -> 'Debug Console' or by pressing CTRL + SHIFT + Y
) to have any logging or errors appear directly in Visual Studio Code. The debug console is interactive, too, so entering code into the input text box below the console will execute it in the game. This can be used to execute Debug.Reload()
which will hot reload the Lua code from inside the code editor (same as pressing F7 in the game).
To use breakpoints, make sure that the folder opened in Visual Studio Code is the top "mods" directory of Desynced and not a specific mod directory inside of it, as it needs to match the path defined in the "sourceRoot" field of the launch configuration.