Flammable Apple wrote: ↑Tue Dec 31, 2024 7:53 pm
So, I might just be stupid but I'm working on a project and for organization I made multiple lua files. On of them,
load.lua contains a function called
fontSetup() and a few other functions on
main.lua I've got:
Code: Select all
function love.load()
love.filesystem.load("load.lua")
love.filesystem.load("draw.lua")
love.filesystem.load("variables.lua")
fontSetup()
physicsSetup()
windowSetup()
end
Later I call
fontSetup() and it returns "nil".
I might just be stupid or not looking hard enough but I can't figure out why
love.filesystem.load("load.lua") won't work.
Hi, welcome to the forums.
In order for your file to define the functions you want, you need to run it. But as stated in the
love.filesystem.load documentation, "Loads a Lua file (
but does not run it)." (bolding added).
Just write it like this:
Code: Select all
love.filesystem.load("load.lua")()
love.filesystem.load("draw.lua")()
love.filesystem.load("variables.lua")()
Note the () at the end. Since it returns a function, adding () forces a call to the function, which effectively runs the file. Alternatively, you could do it like this:
Code: Select all
local load = love.filesystem.load("load.lua")
load()
and similarly for the other files, but it's simpler if you just append the (), isn't it?