Modding: cant use files with same name in different folders

Bugs that are actually features.
Post Reply
Natha
Fast Inserter
Fast Inserter
Posts: 185
Joined: Sun Mar 15, 2015 1:48 pm
Contact:

Modding: cant use files with same name in different folders

Post 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

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

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

Post 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.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

Natha
Fast Inserter
Fast Inserter
Posts: 185
Joined: Sun Mar 15, 2015 1:48 pm
Contact:

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

Post 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 ;)
Last edited by Natha on Sat Jan 23, 2016 7:44 pm, edited 1 time in total.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13226
Joined: Wed Jun 11, 2014 5:23 am
Contact:

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

Post 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
If you want to get ahold of me I'm almost always on Discord.

Post Reply

Return to “Not a bug”