Page 1 of 1

Modding: cant use files with same name in different folders

Posted: Sun Apr 12, 2015 5:02 pm
by Natha
I had a problem just now, and it took me forever to fix it. The game said, that 'xxx' was not a recognized ID of recipe, but i've checked, all commas, {}, ID references etc. were correct. The structure of files was like the following:

--------------------------------------------
- Mod_0.0.0/
- data.lua
- info.json

prototypes/oxygen/data.lua
prototypes/oxygen/fluid.lua
prototypes/oxygen/recipes.lua

prototypes/hydrogen/data.lua
prototypes/hydrogen/fluid.lua
prototypes/hydrogen/recipes.lua
--------------------------------------------
In oxygen/data.lua and hydrogen/data.lua are the same lines of code:

Code: Select all

require("fluid")
require("recipes")
Then I changed the name of oxygen/fluid.lua and oxygen/recipes.lua, and behold, the mod works.

Why it's not possible to have lua-files with same name in different folders (to notice, both data.lua have the same name and that bothers anyone)?

I really hope that's a bug, not a feature :D

Re: Modding: cant use files with same name in different folders

Posted: Tue Apr 14, 2015 5:39 pm
by bobingabout
I think a more "propper" method to do this would be to forget the data.lua in prototypes/oxygen and prototypes/hydrogen and instead add the following to the main data.lua file.

Code: Select all

require("prototypes/oxygen/fluid")
require("prototypes/oxygen/recipes")
require("prototypes/hydrogen/fluid")
require("prototypes/hydrogen/recipes")
I don't know what effects that would have, but it's what I'd do based on what apears in the base game, and other mods I've looked at.

in fact, I don't know what is in each of these files, but I'd probably only have either a prototypes/oxygen.lua and prototypes/hydrogen.lua, or a prototypes/recipes.lua and prototypes/fluids.lua.

From the one perspective, fewer, larger files are good, because smaller files will take an entire sector of space, meaning a 16 byte file will still take 64kb(or whatever your cluster size is) of disk space for each file, and clog up your File Alocation Table. from the other perspective, putting too much code in one file can make it harder to work with when coding.

Re: Modding: cant use files with same name in different folders

Posted: Tue Apr 14, 2015 7:28 pm
by Natha
bobingabout wrote:I think a more "propper" method to do this would be to forget the data.lua in prototypes/oxygen and prototypes/hydrogen and instead add the following to the main data.lua file.

Code: Select all

require("prototypes/oxygen/fluid")
require("prototypes/oxygen/recipes")
require("prototypes/hydrogen/fluid")
require("prototypes/hydrogen/recipes")
I don't know what effects that would have, but it's what I'd do based on what apears in the base game, and other mods I've looked at.

in fact, I don't know what is in each of these files, but I'd probably only have either a prototypes/oxygen.lua and prototypes/hydrogen.lua, or a prototypes/recipes.lua and prototypes/fluids.lua.

From the one perspective, fewer, larger files are good, because smaller files will take an entire sector of space, meaning a 16 byte file will still take 64kb(or whatever your cluster size is) of disk space for each file, and clog up your File Alocation Table. from the other perspective, putting too much code in one file can make it harder to work with when coding.
With oxygen and hydrogen fluid and recipes were examples. In my real mod I add amongst other things new belts and I have for each belt (tier 4 normal, tier 4 underground, splitter, ... up to tier 5) own files (overall currently 20 files). in folder belts/ the data.lua is for me indispensable, because otherwise the main data.lua is too big (further I work with config...)

If i put all requires() in the main data.lua, I lose my clarity in code, (because there are nested config queries), and I wont program without clarity :)

But back2 topic, why you cant use files with same name in different folders ;)

Re: Modding: cant use files with same name in different folders

Posted: Fri Jul 03, 2015 12:51 pm
by Rseding91
This is by Lua design not something we've restricted/canged - you need to specify the path of the file you want to include: http://www.lua.org/pil/8.1.html