Modding/Lua Debugging: Difference between revisions

From Desynced Wiki
(Added notice that the Lua Debugger needs mono on linux. Its a bit hard to spot because it silently fails.)
No edit summary
Line 8: Line 8:
# [https://github.com/StageGames/VSCodeLuaDebugger/blob/main/mobdebug.lua mobdebug.lua] downloaded to the root of the Mods folder (normally in: <code>C:\Program Files (x86)\Steam\steamapps\common\Desynced\Desynced\Content\mods</code>)
# [https://github.com/StageGames/VSCodeLuaDebugger/blob/main/mobdebug.lua mobdebug.lua] downloaded to the root of the Mods folder (normally in: <code>C:\Program Files (x86)\Steam\steamapps\common\Desynced\Desynced\Content\mods</code>)
# [http://steamcommunity.com/sharedfiles/filedetails/?id=3024638463 VSCode-Debugging] from Workshop  
# [http://steamcommunity.com/sharedfiles/filedetails/?id=3024638463 VSCode-Debugging] from Workshop  
Note: <code>vscode-debuggee.lua</code> needs to be edited on line 3, changing <code>require 'socket.core'</code> to <code>require 'socket'</code>.


With the above ready, start the game with <code>-moddev</code> (optionally <code>-log</code> too for better logging output). Once the game has started, enable the <code>VSCode Debugging</code> from the Mod list.
With the above ready, start the game with <code>-moddev</code> (optionally <code>-log</code> too for better logging output). Once the game has started, enable the <code>VSCode Debugging</code> from the Mod list.

Revision as of 03:03, 26 August 2023

Visual Studio Code

In order to debug using Visual Studio code, a few steps first need to be completed:

  1. Lua Debugger VSCode extension. (Requires mono on linux)
  2. Following files downloaded from devcat and placed where the Desynced Binary is (normally in: C:\Program Files (x86)\Steam\steamapps\common\Desynced\Desynced\Binaries\Win64)
    1. dkjson.lua
    2. vscode-debuggee.lua
  3. mobdebug.lua downloaded to the root of the Mods folder (normally in: C:\Program Files (x86)\Steam\steamapps\common\Desynced\Desynced\Content\mods)
  4. VSCode-Debugging from Workshop

Note: vscode-debuggee.lua needs to be edited on line 3, changing require 'socket.core' to require 'socket'.

With the above ready, start the game with -moddev (optionally -log too for better logging output). Once the game has started, enable the VSCode Debugging from the Mod list.

Now in Visual Studio Code, create a folder called .vscode and add a file called launch.json and paste the following content into this file:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Desynced Debugger",
            "type": "lua",
            "request": "attach",
            "workingDirectory": "${workspaceRoot}",
            "sourceBasePath": "${workspaceRoot}",
            "listenPublicly": false,
            "listenPort": 56789,
            "encoding": "UTF-8"
        }
    ]
}

This will create the ability to launch the debugger using Visual Studio Code, using CTRL + SHIFT + D. Once this has been pressed, you will now see Desynced Debugger with a green Play button. Upon pressing the Play button, the debugger will be launched, listening for the game.

Now, in game, either start a new game (or load a save game), or hit Hot Reload (F7) to cause the game to connect. Once connected, you'll have full access to stepping through code, as well as accessing the local and watch windows, etc. You make have to enable Allow Breakpoints Everywhere in your settings to set breakpoints.