Including files / dofile won't work

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
RonanZero
Citizen
Posts: 90
Joined: Mon Oct 20, 2014 3:33 am

Including files / dofile won't work

Post 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:

Code: Select all

include("test.lua")
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... :?
while true do end;
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: Including files / dofile won't work

Post 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.
User avatar
RonanZero
Citizen
Posts: 90
Joined: Mon Oct 20, 2014 3:33 am

Re: Including files / dofile won't work

Post by RonanZero »

Well I can't find any releases/demos with the source. :?
while true do end;
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Including files / dofile won't work

Post by Robin »

You can't find any .loves? Or didn't you yet know that .loves are just zip files containing the game source?
Help us help you: attach a .love.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 3 guests