Using LÖVE with Visual Studio Code

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Nekyia
Prole
Posts: 8
Joined: Thu Aug 03, 2017 4:25 pm

Using LÖVE with Visual Studio Code

Post by Nekyia »

Hello,
I start learning Lua and plan to make games with LÖVE. I want to code with Visual Studio Code.

I have installed and set up 'Code Runner' to launch lua53.exe (lua-5.3.5_Win64_bin) and vscode-lua for Intellisense and Linting.
I see two plugins for LOVE: LOVE by bschulte and Love2D Support by Pixelbyte Studios.

- Should I use another version of Lua?
- I have installed the first plugin. Would you recommand this one rather than the other one?
- And how can I make luacheck work with LÖVE?

Thank you!

Edit: Also installed Lua Debug, which can obviously be helpful
tobiasvl
Prole
Posts: 29
Joined: Mon Oct 01, 2018 4:58 pm
Location: Norway
Contact:

Re: Using LÖVE with Visual Studio Code

Post by tobiasvl »

You don't actually need Lua installed to run LÖVE games. LÖVE comes with everything you need, and by default it uses the LuaJIT interpreter, not Lua 5.3. Launching your LÖVE games in lua53.exe is not going to work; you need to run them with the LÖVE framework.

You can use an extension like Löve Launcher by Jan Werder to do so easily. The one by Pixelbyte Studios also supports launching the project in LÖVE (it is the one I use, I haven't used the one by bschulte).

luacheck and Lua Debug will work with LÖVE as well, but they're going to tell you that "love" is undefined, for example. Not sure if there's a way to fix that, so I just ignore it.
scoobyff666
Prole
Posts: 14
Joined: Fri Sep 16, 2016 5:21 am

Re: Using LÖVE with Visual Studio Code

Post by scoobyff666 »

Dont forget there is the Local Lua Debugger (tomblind.local-lua-debugger-vscode) extension.
This extension will debug love games with break points and all the cool stuff.
Nekyia
Prole
Posts: 8
Joined: Thu Aug 03, 2017 4:25 pm

Re: Using LÖVE with Visual Studio Code

Post by Nekyia »

Thanks to both of you! That was really helpful and I have now everything I need to learn and make games :)
tobiasvl
Prole
Posts: 29
Joined: Mon Oct 01, 2018 4:58 pm
Location: Norway
Contact:

Re: Using LÖVE with Visual Studio Code

Post by tobiasvl »

scoobyff666 wrote: Sun Apr 05, 2020 11:54 pm Dont forget there is the Local Lua Debugger (tomblind.local-lua-debugger-vscode) extension.
This extension will debug love games with break points and all the cool stuff.
Wow, I actually hadn't used this. It seems super useful, but doing require("lldebugger").start() is really resource intensive, it seems. My game drops to about 1 FPS. Also, on Windows, even though I use lovec.exe in the launch.json (and t.console is true, of course), the console window doesn't appear.
Nekyia
Prole
Posts: 8
Joined: Thu Aug 03, 2017 4:25 pm

Re: Using LÖVE with Visual Studio Code

Post by Nekyia »

I put that in user settings.json:

Code: Select all

    "launch": {
        "configurations": 
        [
            {
                "type": "lua-local",
                "request": "launch",
                "name": "Debug LOVE",
                "program":
                {
                    "command": "love"
                },
                "args": 
                [
                    "${workspaceFolder}",
                    "vsc_debug"
                ],
            },
        ]
    },
It sends "vsc_debug" as argument and I have this is the first line of my main.lua :

Code: Select all

if arg[#arg] == "vsc_debug" then require("lldebugger").start() end
But the main point is that I had to put the configuration inside user settings. I don't remember why :oops:
scoobyff666
Prole
Posts: 14
Joined: Fri Sep 16, 2016 5:21 am

Re: Using LÖVE with Visual Studio Code

Post by scoobyff666 »

Well, this may help some people. I put the following lines as the first lines in my main.lua:

Code: Select all

if pcall(require, "lldebugger") then require("lldebugger").start() end
if pcall(require, "mobdebug") then require("mobdebug").start() end
So that this works if you're using vscode and also works for people who choose to use the zerobrane debugger.
Wow, I actually hadn't used this. It seems super useful, but doing require("lldebugger").start() is really resource intensive, it seems. My game drops to about 1 FPS. Also, on Windows, even though I use lovec.exe in the launch.json (and t.console is true, of course), the console window doesn't appear.
Yes it is really expensive. By running this code snippet above, you can still run your game by just running love on the terminal, as you would normally do without this vscode extension, and the debugger will not kick in, making the game perform normally. You can also add protection by a command line argument, like Nekyia suggested, so you can create a rule in vscode that will run without debugging. (I don't use windows so I cannot help about the terminal in windows part, sorry)
Nekyia
Prole
Posts: 8
Joined: Thu Aug 03, 2017 4:25 pm

Re: Using LÖVE with Visual Studio Code

Post by Nekyia »

My love2d extension run 'love --console .' Is this similar to lovec.exe ?
I tried lovec.exe and can't see any difference.
User avatar
pgimeno
Party member
Posts: 3674
Joined: Sun Oct 18, 2015 2:58 pm

Re: Using LÖVE with Visual Studio Code

Post by pgimeno »

Nekyia wrote: Wed Apr 15, 2020 8:07 am My love2d extension run 'love --console .' Is this similar to lovec.exe ?
I tried lovec.exe and can't see any difference.
I don't have Windows, so I can't tell for sure, but I believe lovec.exe is a "console application", meaning it's the OS who creates and attaches the console, while with love --console, it's Löve itself the one creating and attaching the console. I remember an old thread where the latter caused problems with some editor (Sublime?); maybe it's not the case for VSC or maybe that issue is fixed in a newer version.
davidgallagher
Prole
Posts: 1
Joined: Thu Jul 16, 2020 3:19 pm

Re: Using LÖVE with Visual Studio Code

Post by davidgallagher »

Hi everyone,

I'm new to coding and just trying to get set up with a Lua/LOVE2D debugger in VS Code on a MacBook Pro. I don't understand anything about JSON, executables, etc. and just want to get Lua Love Debugger by Tom Blind up and running so that I can debug. Could someone please walk me through the steps I need to do to get set up. I'm currently using Love2D Support by Pixelbyte Studios to run the programs, but it doesn't appear to have a debugger for Mac.

Thanks!
Post Reply

Who is online

Users browsing this forum: Amazon [Bot], Bing [Bot], Google [Bot] and 7 guests