0

so i downloaded love2d and its in program files and added it to the environment variables and opened vs code and downloaded the extension of love2d support and i did everything like the video on youtube right and its still now working, it says undefined global love so if anyone can please help me and i found that someone said that you can drag the main.lua file in the love2d app and it should work but it doesnt work for me also so please help and thank you. enter image description here enter image description here enter image description here enter image description here enter image description here

i tried everything other extensions and nothing works, i even downloaded it on my ither leptop and same problem and i my friend also has the same exact problem

4
  • I believe this is an issue with the extension. I get the same error. After disabling the extension the error is also gone. Commented Jun 8, 2024 at 20:02
  • It looks like Lua LSP doesn't have enabled love2d 3rd party workspace support, try to look at Lua LSP settings or contact extension authors Commented Jun 10, 2024 at 9:19
  • Also to run Love2D, you can just open command prompt and run love . (assuming you are in folder with main.lua), or drop folder containing main.lua onto love.exe Commented Jun 10, 2024 at 9:32
  • Yes, by default the lua language server does (no longer?) load love2d by default, it needs to be added. The process changed a bit recently with the introduction of an addon manager: luals.github.io/wiki/definition-files Commented Jun 11, 2024 at 8:49

2 Answers 2

0

The lua language server (lls) doesn't require love by default so, add this at every first line of any lua file that uses the love table.

also with the love support extension you can use alt+l in order to run the project your in.

local love = require("love")
Sign up to request clarification or add additional context in comments.

Comments

0

You will want to install two extensions; the love2d support extension and the lua extension so you have the language server which provides syntax highlighting and error checking. Do read their installation instructions.

This is not enough to complete the setup. To get rid of the undefined 'love' global error, you will want to, in an opened project, do the following:

  • open the Visual Studio Code command palette (under the "View" menu)
  • Search for "lua addon manager" and open it
  • In the lua addon manager you will want to look for LOVE (should be at the top) and enable it.

This will resolve the undefined global error for this project. If you start a new project, you will need to repeat these steps.

Worth noting is that there are several versions of Lua that the language server supports; from Lua 5.1 to 5.4 and also LuaJIT. Love2d by default uses LuaJIT for performance reasons. LuaJIT is limited to the Lua 5.1 feature set, so something like the \\ operator which does an integer division is not supported. When starting a new project it is worth it to check that the Lua extension is configured for LuaJIT so the extension will warn you when you are using unsupported features, which should already be the case if you activated LOVE support as per the above instructions. You can do this by:

  • Opening the extensions in the left menu
  • Clicking on the gear next to the installed "lua" extension and then clicking "settings"
  • In the search box at the top search for "lua runtime version" and make sure "LuaJIT" is selected in the select box.

Finally most documentation will tell you that you can run your Love2d project from Visual Studio Code using the ALT+L keyboard shortcut. This is likely to conflict with other extensions though. If it doesn't work, you should change the key binding to something like ALT+SHIFT+L. You can do this by taking the following steps:

  • Open the visual studio code keyboard shortcuts (under File -> Preferences)
  • In the search box at the top, search for "love2d"
  • The keyboard shortcut you will want to change is the one named "Run Love2D on the workspace folder".

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.