data, data-updates and data-final-fixes

Place to post guides, observations, things related to modding that are not mods themselves.
Post Reply
User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2903
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

data, data-updates and data-final-fixes

Post by darkfrei »

Here is a lot of mods, that can't working with another mods while they are have wrong access order to data.raw
Here is a very good example.
The whole mod has only data.lua with this code:

Code: Select all

for k, v in pairs(data.raw.resource) do
   data.raw.resource[k].infinite = true
   data.raw.resource[k].minimum  = 100
   data.raw.resource[k].normal   = 100
end
Do you know why it doesn't work with bob ores, angel ores and 5dim ores?

Sunnova
Fast Inserter
Fast Inserter
Posts: 169
Joined: Mon May 16, 2016 12:10 pm
Contact:

Re: data, data-updates and data-final-fixes

Post by Sunnova »

Make sure to place those mods in your dependencies list in your mods info.json file, so they get loaded before your mod does.

darkfrei wrote:
Do you know why it doesn't work with bob ores, angel ores and 5dim ores?

orzelek
Smart Inserter
Smart Inserter
Posts: 3911
Joined: Fri Apr 03, 2015 10:20 am
Contact:

Re: data, data-updates and data-final-fixes

Post by orzelek »

It's a very generic question.
If you use dependencies and data-final-fixes it should work correctly.
In most cases final fixes are enough - but then you get more and more mods doing stuff in final fixes.

Dependencies are better choice but you need to know beforehand that other mods will modify same things you did.
A lot depends on how mods are written - main difference is if mod is only modifying base game stuff or it has full definitions copied inside it.

Looking at the example mod I'd say you should use final fixes. Aim of the mod is to overwrite ore settings for all ores.
You still might need to add dependencies if other mods modify ores in their final fixes - it should be rare but might happen.

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3699
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: data, data-updates and data-final-fixes

Post by DaveMcW »

data.lua - Add new resources.
data-updates.lua - Modify another mod's new resources.
data-final-fixes.lua - Last chance to change things, avoid this if you can to minimize conflicts.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: data, data-updates and data-final-fixes

Post by eradicator »

DaveMcW wrote:data.lua - Add new resources.
data-updates.lua - Modify another mod's new resources.
data-final-fixes.lua - Last chance to change things, avoid this if you can to minimize conflicts.
Exactly this. You should use optional dependencies AND data-updates.lua to change ores.

Unless your aim is to change every ore even in mods you don't know anything about, in which case final-fixes gives you higher chances of succeeding. But changing ores of mods that you don't even know is a very bad idea in the first place. Especially if you're messing with the amounts. You might completely destroy the balance of a mod by making slow-to-extract resources extremely fast/common or fast-to-extract resources extremely slow/rare. (I know this because i can already see how this would mess up one of my WIP mods that uses highly variable infinite resources. Also another part of that mod uses "resource" prototypes to simulate some stuff which would also completely break if someone messed with the amount values.)
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2903
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: data, data-updates and data-final-fixes

Post by darkfrei »

eradicator wrote:Also another part of that mod uses "resource" prototypes to simulate some stuff which would also completely break if someone messed with the amount values.)
How are you using this prototypes? To send some information from data to control? viewtopic.php?f=28&t=53615

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: data, data-updates and data-final-fixes

Post by eradicator »

darkfrei wrote:
eradicator wrote:Also another part of that mod uses "resource" prototypes to simulate some stuff which would also completely break if someone messed with the amount values.)
How are you using this prototypes? To send some information from data to control? viewtopic.php?f=28&t=53615
No. It's nothing like that. Its part of an environment simulation that uses unminable resources to determine some values for the surrounding area. And it relies (amongst others) on the resource amount to get decent random properties.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

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

Re: data, data-updates and data-final-fixes

Post by bobingabout »

darkfrei wrote:Here is a lot of mods, that can't working with another mods while they are have wrong access order to data.raw
Here is a very good example.
The whole mod has only data.lua with this code:

Code: Select all

for k, v in pairs(data.raw.resource) do
   data.raw.resource[k].infinite = true
   data.raw.resource[k].minimum  = 100
   data.raw.resource[k].normal   = 100
end
Do you know why it doesn't work with bob ores, angel ores and 5dim ores?
Basically, the ores in my mod do not FULLY exist until the end of the data-updates phase...
The item and resource is added in the data phase.
the autoplace controls are added in the data-updates phase

what you're doing in that loop will only work after my data.lua has been run, so, to do that, you either need to add bob's ores as a (optional) dependency to force it to load first, or the easy solution (and the reason why it exists) is to put that in the data-updates.lua instead (because then it will run in the data-updates phase, AFTER the data phase, after my mods have added ores).



Anyway, what you're doing there already exists in bob's ores mod. one of the options in the ingame menu is to turn all ores infinite. and, the script is basically the same as yours.

Code: Select all

if settings.startup["bobmods-ores-infiniteore"].value == true then
  for index, resource in pairs(data.raw.resource) do
    if not resource.infinite then resource.infinite = true end
    if not resource.minimum then resource.minimum = 35 end
    if not resource.normal then resource.normal = 350 end
  end
end
note the use of the if not in there, that means it isn't going to overwrite stuff that already has this tag set, like oil.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

Post Reply

Return to “Modding discussion”