Code Changes Aren't Reflected when Running Love

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
sjyn291
Prole
Posts: 2
Joined: Thu Dec 03, 2020 2:53 am

Code Changes Aren't Reflected when Running Love

Post by sjyn291 »

Hi All,
I'm relatively new to Love, so I hope I'm not making some dumb mistake here. I'm running Lua 5.3.5 on macOS Catalina and have made a "class" in a file at renderer/renderer.lua in my project. It currently looks like

Code: Select all

local Renderer = {}

function Renderer:Create(o)
  print('creating')
  t = o or {}
  setmetatable(t, self)
  self.__index = self

  return t
end

-- setup the renderer state based on the engine state
function Renderer:Update(engine)
  print('update renderer')
end


-- pass in the engine and choose the correct renderers to draw based on engine.states
function Renderer:Draw(engine)
  print('draw renderer')
end

return Renderer
Originally, I did not have an Update function, and was just calling the Draw function in the main.lua as such:

Code: Select all

local Renderer = require('./renderer/renderer')
local renderer = nil

function love.load()
  renderer = Renderer:Create()
end

function love.update()
  -- no updating here, yet
end

function love.draw()
  renderer:Draw()
end
After implementing the Update function in the Renderer table, I changed the update method to

Code: Select all

function love.update()
  renderer:Update()
end
All files have been saved and I've even restarted my machine, but running love . in my project directory just pops up the game window with the error

Code: Select all

Error: main.lua:16: attempt to call method 'Update' (a nil value)
stack traceback:
        [string "boot.lua"]:777: in function 'Update'
        main.lua:16: in function 'update'
        [string "boot.lua"]:612: in function <[string "boot.lua"]:594>
        [C]: in function 'xpcall'
Additionally, changes to Renderer:Draw are no longer recognized. Changes to other files are seen by Love. What the heck is going on here? Is this a Love issue or a Lua issue? I was unable to find anyone else who's had this issue. Any help would be appreciated!
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Code Changes Aren't Reflected when Running Love

Post by zorg »

Hi and welcome to the forums;

A few things i notice that may or may not play a role in the issues you're having, but are still errorenous:

- Löve by default uses luaJIT, which is lua 5.1 with some 5.2 features; i'm not sure why or how you're using "Lua 5.3.5", since löve should include luajit with itself, unless you built it yourself deliberately like that.

- require takes in module names, not paths; instead of './renderer/renderer' you want 'renderer.renderer'

Apart from these, we'd probably need to ask for you to share the whole codebase (or better yet, a minimal one that still reproduces the issue) to actually know why file changes aren't recognized... assuming the changed files are saved, your folder structure is correct, etc.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
sjyn291
Prole
Posts: 2
Joined: Thu Dec 03, 2020 2:53 am

Re: Code Changes Aren't Reflected when Running Love

Post by sjyn291 »

Thanks for the quick reply!
Apologies for the Lua version misunderstanding. I assumed Love was using whatever Lua was on my path.

Also, this is indeed not a Love issue. Turns out the t variable in the Renderer:Create() function is at a global scope, and another module is performing similar logic with a variable named t, so the metatable was getting overwritten. Making those variables local fixed the issue.

Thanks again!
Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests