Page 1 of 1
Including files / dofile won't work
Posted: Mon Oct 20, 2014 5:48 pm
by RonanZero
OK I want to include a separate file for organization. E.G. file names would be main.lua, draw.lua, sound.lua, ai.lua etc.
In GLua (Garry's Mod Lua) you would just do this:
But of course include isn't in Love2D so I tried using dofile("draw.lua") now it DID load that file, but I'm not sure whether the love.draw() in draw.lua is fully overriding the one in main.lua or if it just only loads draw.lua. I want not everything to be in the same function/file so it would be useful for a way to "hook" things to love.draw instead of a full overwrite? Any way? Or is it dofile's problem...
Re: Including files / dofile won't work
Posted: Mon Oct 20, 2014 6:08 pm
by Roland_Yonaba
What you need is
require.
Technically, I think
dofile should be supported (I am very unsure about that, though). But anyway,
require is definitely a more elegant solution. That function is meant to require *.lua modules, libraries and dependencies, external code.
LÖVE has its built-in equivalent, named
love.filesystem.load.
EDIT:
In my opinion, you should take a look at some people *.love projects (in the Project and Demos section) and see how their organize their code when they split it in multiple files and use require. It'll certainly help.
Re: Including files / dofile won't work
Posted: Mon Oct 20, 2014 6:40 pm
by RonanZero
Well I can't find any releases/demos with the source.
Re: Including files / dofile won't work
Posted: Mon Oct 20, 2014 9:32 pm
by Robin
You can't find any .loves? Or didn't you yet know that .loves are just zip files containing the game source?