Learn how to program games with the LÖVE framework

Visual Studio Code

Visual Studio Code is a code editor by Microsoft with lots of features. In this chapter we go over some extensions and tricks to optimize the editor for making LÖVE games.

Install Visual Studio Code

Template

Check out Keyslam's LÖVE VSCode Game Template for a template. This tutorial does not use the template, but explains how you can manually add and configure the extensions that you can also find in the template.

Extensions

Install the following extensions:

Lua

As the marketplace says this extension gives you lots of useful features. We can also make it have LÖVE autocomplete.

Press Ctrl + Shift + P and look for and open Preferences: Open User Settings (JSON).

Add the following settings to the JSON:

{
    "Lua.runtime.version": "LuaJIT",
    "Lua.diagnostics.globals": [
        "love",
    ],
    "Lua.workspace.library": [
        "${3rd}/love2d/library"
    ],
    "Lua.workspace.checkThirdParty": false,
}

Local Lua Debugger

Add the folder where love.exe is located to your environment variables. In Windows search for Edit the system environment variables. At the bottom click on Environment Variables. In System variables search for and click on Path. Click Edit.... Click New. Type the path to the folder where your love.exe is located.

Guide

Now we are going to add two launchers. Note that the following approach is not necessarily the best. This is a personal preference.

Go to Run and Debug (play button with a bug on the left). Click on create a launch.json file.

Replace the contents of the new file with this:

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "lua-local",
      "request": "launch",
      "name": "Debug",
      "program": {
        "command": "love"
      },
      "args": [
        ".",
        "debug"
      ],
    },
    {
      "type": "lua-local",
      "request": "launch",
      "name": "Release",
      "program": {
        "command": "love"
      },
      "args": [
        ".",
      ],
    },
  ]
}

Add the following line at the top of your main.lua:

if arg[2] == "debug" then
    require("lldebugger").start()
end

You can press F5 to start the launcher. You can select which launcher you want to use in Run and Debug. You now have two ways to launch LÖVE:

We can improve the debugger by making it highlight an error when we get one. For this we will need to edit love.errorhandler. LÖVE catches the error to show the nice error screen, but we want it to actually throw an error.

At the bottom of main.lua add the following code:

local love_errorhandler = love.errorhandler

function love.errorhandler(msg)
    if lldebugger then
        error(msg, 2)
    else
        return love_errorhandler(msg)
    end
end

Now when you get an error in Debug mode Visual Studio Code will jump to the file and line of where the error occured and highlight it, along with the error message.

error

You might notice that your game slows down a lot in Debug mode. This only happens when you have break points, so remember to disable those if you don't use them.

You can also expand on this, like showing debug information on screen when launch_type == "debug".

Building

Now we want to make it easy to build our project.

makelove

We use the builder makelove.

  1. Install Python (if you do a custom installation make sure to install pip).
  2. Open a terminal (e.g. Windows Powershell) and type pip3 install makelove.
  3. In your game's folder (where you have your main.lua) create a file called make_all.toml and add the following:
    name = "Game"
    default_targets = ["win32", "win64", "macos"]
    build_directory = "bin"
    love_files = [
    "+*",
    "-*/.*",
    ]

Tasks

Press Ctrl + Shift + P and look for and open Task: Configure Task. Select Create task.json file from template. Select Others (or any other, doesn't really matter). Replace the file's contents with this:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Build LÖVE",
            "type": "process",
            "command": "makelove",
            "args": [
                "--config",
                "make_all.toml"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        },
    ]
}

Now in Visual Studio Code you can press Ctrl + Shift + B to run the task. This will create a bin folder, with inside folders that have .zip files inside of them.

Do you need help or do you see a mistake?
Leave a comment or edit this chapter.

Wishlist my upcoming game To Bring Her Back on Steam!