How can I use Love2d in Visual Studio Code?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
InTheProcess
Prole
Posts: 11
Joined: Thu May 27, 2021 4:19 pm

How can I use Love2d in Visual Studio Code?

Post by InTheProcess »

I have been trying to get the Love2d-made-easy extension to work. I have installed all of the requirements and made the "love" code snippet a global variable, but as soon as I try to run it, it will say "love isn't recognized as an internal or external command". Then, the extension says "Running love2d game...", but nothing happens. I don't know what to do, PLEASE HELP!




Love2d-made-easy extension ->
https://marketplace.visualstudio.com/it ... -made-easy
gcmartijn
Party member
Posts: 134
Joined: Sat Dec 28, 2019 6:35 pm

Re: How can I use Love2d in Visual Studio Code?

Post by gcmartijn »

I'm using visual studio code + osx + lua for some years now.
Only with those extensions, but I only needed the last two I guess.

- Love2D Support pixelbyte-studios.pixelbyte-love2d
- vscode-lua trixnz.vscode-lua
- Code Runner formulahendry.code-runner

Then I have a "play now" button in the right corner and when I press it , it will start the program.

In the workspace I have .vscode/settings.json

Code: Select all

{
    "code-runner.clearPreviousOutput": true,
    "code-runner.enableAppInsights": false,
    "code-runner.customCommand": "",
    "code-runner.defaultLanguage": "lua",
    "code-runner.executorMapByGlob": {
        "*.lua": "$workspaceRoot/scripts/run.sh"
    },
    "code-runner.showRunCommandInExplorerContextMenu": false,
    "code-runner.showRunCommandInEditorContextMenu": false,
    "code-runner.saveFileBeforeRun": true,
    "code-runner.saveAllFilesBeforeRun": true,
    "editor.formatOnSave": true,
    "editor.formatOnPaste": true
}
As you can see I can press the play button in every *.lua file, this will start a .sh script that I made inside scripts

scripts/run.sh

Code: Select all

/Applications/love.app/Contents/MacOS/love /Users/$USER/Documents/MvB/game/src
There is a .vscode/tasks.json but I don't know why anymore

Code: Select all

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Love2d",
            "type": "shell",
            "command": "/Applications/love.app/Contents/MacOS/love ${workspaceRoot}/src",
            "problemMatcher": []
        }
    ]
}
And there is a .vscode/launch.json

Code: Select all

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "lua",
            "request": "launch",
            "name": "Launch",
            "program": "${workspaceFolder}/main.lua"
        }
    ]
}
every

Code: Select all

print("hello")
Is visible in the VSC code output


edit 11 june 2021
the latest visual studio code: go to settings and search: trust
disable the option : Controls whether or not workspace trust is enabled with VS Code
Last edited by gcmartijn on Fri Jun 11, 2021 6:45 pm, edited 1 time in total.
gcmartijn
Party member
Posts: 134
Joined: Sat Dec 28, 2019 6:35 pm

Re: How can I use Love2d in Visual Studio Code?

Post by gcmartijn »

ow and there is a global user settings.json

Code: Select all

{
    "telemetry.enableCrashReporter": false,
    "telemetry.enableTelemetry": false,
    "explorer.confirmDelete": false,
    "editor.minimap.enabled": false,
    "explorer.confirmDragAndDrop": false,
    "pixelbyte.love2d.runOnSave": true,
    "pixelbyte.love2d.path": "/Applications/love",
    "files.autoSave": "off",
    "workbench.startupEditor": "newUntitledFile",
    "diffEditor.ignoreTrimWhitespace": false,
    "lua.format.useTabs": null,
    "javascript.updateImportsOnFileMove.enabled": "never"
}
InTheProcess
Prole
Posts: 11
Joined: Thu May 27, 2021 4:19 pm

Re: How can I use Love2d in Visual Studio Code?

Post by InTheProcess »

oddly enough, I reopened vsc and created a new file. Works great, lol
klewis
Prole
Posts: 7
Joined: Fri Jan 10, 2020 1:54 pm

Re: How can I use Love2d in Visual Studio Code?

Post by klewis »

For my setup in VSCode on Windows 10 here is what I do from the very start to finish :
  • Download and install the latest version of VSCode
  • Download and install LOVE app (64 bit) for Windows 10
  • Go to your environmental variables and add LOVE to path (we'll use this later to run commands from the terminal)
  • Download and install the latest version of Github Desktop
  • From Github Desktop, create a new local repository for your LOVE project and open it up in VSCode
  • Now that you are inside of VSCode, I would also create a new workspace directory for the environment. Give it a name identical to what you named it when you created your repository in Github Desktop
  • Exclusively for your workspace, download the following extensions : Lua | Lua Debug | Love2D Support | Love2D Snippets | Path Autocomplete | vscode-lua | vscode-lua-format | Auto Close Tag | Auto Rename Tag | Duplicate Action | image preview. FYI - there's some cool stuff you can do with each of these extensions. You just have to site down and take time to explore each one.
  • Within this new workspace create your main.lua file. This file is a core component for your game.
  • When you are ready to run your project out of VSCode, simply press Alt + L to run the project
  • When you decide to go beyond the above steps, and later desire to create sub games, you can do that in this same workspace! From this workspace, create a new sub folder -> inside of it, create a main.lua file with its own gaming logic. Go back to the parent directory of the workspace, and open the terminal. Now from the terminal run love <name-of-sub-folder>. This will run your sub folder games in this same workspace!
  • Last! When you are done coding, either in chuncks, or perhaps for the day, go back into GitHub Desktop and commit your work, and push it out to Github so you have a reliable backup of your progress.

If anyone has any adjustments to improve this listing, please feel free to add!
Post Reply

Who is online

Users browsing this forum: No registered users and 60 guests