Including files from another directory?

I have already checked another thread about this and its not working.



-- In the autorun/slemp.lua file
local files, directories = file.Find( "entities/bed/shared*", "LUA" )
include(files[1])

-- In the entities/bed/shared.lua file
local files, directories = file.Find( "autorun/slemp*", "LUA" )
include(files[1])


Weirdest part is how it tells me “Couldn’t include file ‘shared.lua’ (File not found)” because it seems to find the file based on the fact that it knows it has .lua after it.

it is because you’re trying to include file name without the folder. you should add folder in front. try it like;



include(directories[1].."/"..files[1])

You also may need to add the folder name that you are searching for, manually. For example if you are looking for files in “daenerys/dragon” then you should do it like;


local files, folders = file.Find("daenerys/dragon/*","LUA") 
include("daenerys/dragon/"..folders[1].."/"..files[1])

or, if there is no folders in “daenerys/dragon” then;


local files, folders = file.Find("daenerys/dragon/*","LUA") 
include("daenerys/dragon/"..files[1])

so you have to check if the file is in another folder or not.

heres example usage of file.Find from gmod wiki



local files, directories = file.Find( "*", "DATA" )

print( "File: " .. files[1], "Folder: " .. directories[1] )

File: helloworld.txt
Folder: ctp

Problem is, the file I am trying to include is in another folder that is outside of the local directory itself which means your first example wouldn’t work either as include always starts on the directory the script is ran from no matter what.

Does this mean doing stuff like including lua/thing.lua in the file lua/autorun/thing2.lua is completely impossible?

Edit: Found this on maurits wiki: “…” - this is the special folder name to go up a folder. - Doesn’t work tho ;-;

it is not impossible. did you check my second example? it should help you

According to the wiki page for

include, the file can be “either relative to the current file, or absolute(relative to the /lua/ folder)”. This means you should be able to use include(“entities/bed/shared.lua”) regardless of where you are.

I think the problem is the format of the output file.Find gives you.

Your second example would search for the file like this: localdir/daenerys/dragon/"…folders[1]…"/"…files[1]

The format is not wrong, already checked that and I noticed it said that on the wiki but it never says how to.

I’m just going to put the file i’m trying to include in the same directory as the entities and use some kind of database to transfer the variables between them.

Make sure you AddCSLuaFile in the server init.lua BEFORE including it on the client… That is what happens in most cases when a file isn’t found when everything is typed in correctly…

I recommend setting up your inclusion list like this: https://www.dropbox.com/s/ja9yr507r8nb3hu/gm_name.rar?dl=0

Everything in shared.lua or sh_init.lua as I call it - then you only have one inclusion list to worry about, and everything can be done in order and nicely… That rar file has a simple include file helper function -