skip to Main Content

I have gone through Love2D’s site for set up and watched multiple tutorials on set up for mac:

The version is 11.4. I have checked that I can run Love2D (evidenced by the animation of a blue sky with a duck balloon with a tail phrase "NO GAME", as expected)

I have a "Game" folder on my desktop with one file inside: "main.lua" with code:

function love.draw()
  love.graphics.print("Hello World!", 400, 300)
  end

I have installed the "Love2D Support" extension in VSCode and found the correct file path for my Mac which is: /Applications/love.app/Contents/MacOS/love

That path must be correct because the game will actually run "Hello world" in its own window BUT ONLY when "RunOnSave: True". So, I have to change something (a space here or there) and and save in order for it to run. BUT WHY? I don’t want to get stuck down the line not being able to troubleshoot this. And also, perhaps I don’t want to constantly have it run every change I make. I want to be able to chose "run" through the terminal and or drag and drop.

Things I tried according to the tutorials and all the forums so far that do not work:

Drag and drop the game root folder containing main.lua onto Love to run (does not do anything, no error, no response at all.)

Shortcut Command + L (does not do anything, no error, no response at all.)

Utilize VS Code’s Run without Debugging and get an alert popup "Missing ‘program’ to debug" with choices of "Open launch.json" or "Cancel". If I choose the former, VS Code creates a directory ".vscode" with file "launch.json" in the game’s root folder and the debugger throws exception:

Exception has occurred: main.lua:1: attempt to index a nil value (global 'love')
stack traceback:
    main.lua:1: in main chunk
    [C]: in ?

And if I step over the exception I am seeing this in the terminal (or perhaps this is displaying in the terminal during the initiation of the run (note: "user" is placeholder):

[computer root placeholder] Games %  /Users/user/.vscode/extensions/actboy168.lua-debug-1.61.0-da
rwin-arm64/runtime/darwin-arm64/lua54/lua -e dofile"/Users/user/.vscode/extensions/actboy168
.lua-debug-1.61.0-darwin-arm64/script/launch.lua";DBG"2200" /Users/user/Desktop/Games/mai
n.lua 
/Users/user/.vscode/extensions/actboy168.lua-debug-1.61.0-darwin-arm64/runtime/darwin-arm64/lua54/lua: /Users/user/Desktop/Games/main.lua:1: attempt to index a nil value (global 'love')
stack traceback:
        /Users/user/Desktop/Games/main.lua:1: in main chunk
        [C]: in ?

I have attempted to search for this message but it’s not specific enough to get a good answer.

2

Answers


  1. The Error says nil to love so try…

    love = require('love') -- Should link/declare/load/point to: _G['package']['loaded']['love']
    
    function love.draw()
      love.graphics.print({{0, 0.999, 0, 1}, "Hello World!"}, 400, 300) -- Color: {{Red, Green, Blue, Alpha}, "STRING"}
    end
    

    ( I love LÖVE 🙂 ) so lets move…

    -- main.lua
    -- Declare/Define whats needed
    love = require('love') -- Should link/declare/load/point to: _G['package']['loaded']['love']
    os = require('os')
    
    function love.draw()
      love.graphics.print({{0, 0.999, 0, 1}, ("%sn%sn%.6f"):format("Hello World!", os.date("%T"), os.clock())}, tonumber(os.date("%S")), tonumber(os.date("%S")))
    end
    
    Login or Signup to reply.
  2. If your Shortcut Command + L does not work, check your keybidings.json(Preferences(cmd + ,)->keyboard shortcuts->An icon of "Open keyboard shortcuts(JSON)" on the top-right sub-menu) if there are any conflicts on the same key, or try adding below.

    // Place your key bindings in this file to override the defaults
    [
      {
        "key": "cmd+l",
        "command": "pixelbyte.love2d.run",
        "when": "editorTextFocus && editorLangId == 'lua'"
      }
    ]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search