I can't make my mod work.

Place to get help with not working mods / modding interface.
Post Reply
VBMeireles
Inserter
Inserter
Posts: 23
Joined: Mon Aug 11, 2014 1:34 pm
Contact:

I can't make my mod work.

Post by VBMeireles »

I've copied the "locale" and "prototype" folders from the game's "base" directory into a new folder ("vbmod") inside the game's "mods" directory and changed some of its .lua files (to modify chest capacity and item stack sizes). I've even created an info.json file and put it inside my "vbmod" folder. The "mod" is recognized and active in the game but to no effect at all. What else do I need to do?

User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: I can't make my mod work.

Post by FreeER »

If you didn't copy the data.lua file then Factorio won't actually be loading the prototypes.
It loads the data.lua which then requires all of the files the mod author has created, technically all prototypes could be placed in data.lua, but they're almost always separated for organization reasons.
I'm not sure that the locales are actually needed...but they wouldn't be for the method below (unless you add new prototypes of course, in which case the base locales won't help except as a template)

The 'proper' way to change things would actually be to use something like

Code: Select all

data.raw["prototype_type"]["prototype_name"].property = newValue
for example to change the wooden-chest's inventory size you'd use

Code: Select all

data.raw["container"]["wooden-chest"].inventory_size = 32
This is preferable since you only change the parts of the prototype that you need to change (instead of overwriting the entire prototype) and so is more compatible with other mods (and is a bit shorter...), it also means that if the base game is updated so that it needs another property to load then you don't have to go back and change anything (theoretically). But if you don't plan to release the mod and don't use any mods that would conflict with your overwrites then...it doesn't matter too much as long as you get it working :)

If that doesn't help you get your mod working I'd suggest uploading it and providing a link so that we (other modders) can look at it ourselves.

VBMeireles
Inserter
Inserter
Posts: 23
Joined: Mon Aug 11, 2014 1:34 pm
Contact:

Re: I can't make my mod work.

Post by VBMeireles »

Thank you very much for the explanation! I think I'll be able to get it working now.

However, for example, how is my data.lua file going to look like if I want to, say, change the wooden chest and iron chest capacities to 50?
Will it look like this?

Code: Select all

data.raw["container"]["wooden-chest"].inventory_size = 50
data.raw["container"]["iron-chest"].inventory_size = 50
Is there a shorter/cleaner way of changing the same property of an array of items or something? I'm asking this because I saw this console command to research all of the technologies and I was wondering if I could do something similar to set the capacity of all of the game's containers.

Code: Select all

for _, container in pairs(game.player.force.technologies) do container.inventory_size = 50 end
data.raw["container"]["iron-chest"].inventory_size = 40
data.raw["container"]["wooden-chest"].inventory_size = 20

User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: I can't make my mod work.

Post by FreeER »

VBMeireles wrote:Will it look like this?
yes
VBMeireles wrote:I could do something similar to set the capacity of all of the game's containers.
yep, a simple for loop would work here :)

Code: Select all

for key, prototype in pairs(data.raw["containers"]) do
  -- the 'key' variable isn't used in this example, so you'd typically see people use _ for it
  if prototype.inventory_size < 50 then prototype.inventory_size = 50 end
  -- if you just set it to 50 you could overwrite a larger value
end
if you wanted only specific containers then you could have an if statement checking if the key exists in another table of names (one that you created) and the inventory if statement nested within the name if statement (lua doesn't have a continue statement, if that means anything to you, if not then ignore that fact :)).

VBMeireles
Inserter
Inserter
Posts: 23
Joined: Mon Aug 11, 2014 1:34 pm
Contact:

Re: I can't make my mod work.

Post by VBMeireles »

FreeER wrote:lua doesn't have a continue statement, if that means anything to you, if not then ignore that fact :)
Unfortunatelly it doesn't. LOL. That's so sad, though. I've graduated in Law (though I'm not a lawyer) but I've also done 2 years of Science of Computing (it's a 5-year graduation here in Brazil), used to program and stuff but no longer. :( I miss the good old days of messing with C and its derivatives. I'll definitely read some Lua in order to get into Factorio modding, though.

Post Reply

Return to “Modding help”