My settings gets overwritten by another mods

Place to get help with not working mods / modding interface.
Post Reply
Leoncio
Burner Inserter
Burner Inserter
Posts: 11
Joined: Sun Mar 12, 2023 10:17 pm
Contact:

My settings gets overwritten by another mods

Post by Leoncio »

Hello,

I was wondering if someone could help me with trying to find out if its possible for me, to not have one of my settings get overwritten by another mod?

The script that I want to "overwrite" ( don't know the proper terminology) another mods settings is:

My settings.lua code:

Code: Select all

data:extend({
    {
        type = "bool-setting",
        name = "vanilla-flashlight",
        setting_type = "startup",
        default_value = false,
        order = "j"
    },
})
and the script for "vanilla-flashlight" is on another .lua with the code:

Code: Select all

if settings.startup["vanilla-flashlight"].value then
    data.raw["character"]["character"]["light"] = off
end

The code works fine when I load it by it self, or with mods that don't interfere with the

Code: Select all

data.raw["character"]["character"]["light"] = off
command or with the "if-then-end" setting (don't know what to call it) that it has, but when I load it with the "Gear Girl Character" -mod by SleepyEngi, their script that also has configured the character light takes precedence of my code. Is there I way that I can force my code to overwrite theirs if my setting are active, and revert back to their code if my settings are not active?

Cheers,

Pi-C
Smart Inserter
Smart Inserter
Posts: 1659
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: My settings gets overwritten by another mods

Post by Pi-C »

Leoncio wrote:
Thu Apr 06, 2023 12:36 am
The code works fine when I load it by it self, or with mods that don't interfere with the

Code: Select all

data.raw["character"]["character"]["light"] = off
command or with the "if-then-end" setting (don't know what to call it) that it has, but when I load it with the "Gear Girl Character" -mod by SleepyEngi, their script that also has configured the character light takes precedence of my code. Is there I way that I can force my code to overwrite theirs if my setting are active, and revert back to their code if my settings are not active?
Gear Girl doesn't overwrite your setting (last time it was updated is about 2 years ago, while your mods are more recent), but it will overwrite the default character with its own properties, and among these is the "light" property.

I suppose the setting you refer to is for a new (still unpublished) version of your "Flashlight Weapon" mod. If this is correct, you'd see something like this in your log on starting Factorio:

Code: Select all

   1.708 Loading mod core 0.0.0 (data.lua)
   1.760 Loading mod base 1.1.80 (data.lua)
   1.962 Loading mod flashlight_weapon 0.0.1 (data.lua)
   1.979 Loading mod GirlCharacter 1.0.7 (data.lua)
   2.009 Loading mod base 1.1.80 (data-updates.lua)
   2.024 Loading mod GirlCharacter 1.0.7 (data-final-fixes.lua)
As you can see, GirlCharacter (the mod that adds Gear Girl) is loaded after your mod. Also, Girl Character will become active again in data-final-fixes. This is where the damage is done because GirlCharacter decides that it must overwrite the default character as it couldn't find an active character selector mod.

The solution would be to force GirlCharacter to act before your own mod. This can be done by adding a (possibly hidden) optional dependency on GirlCharacter to your mod:

Code: Select all

-- Optional dependency:
"dependencies": ["? GirlCharacter"],

-- Hidden optional dependency:
"dependencies": ["(?) GirlCharacter"],
You then have several options:
  • Change data.raw.character["GearGirl-skin"].light in data.lua.
  • Change data.raw.character.character.light in data-final-fixes.lua (GirlCharacter will have overwritten the default character at this point).
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

Leoncio
Burner Inserter
Burner Inserter
Posts: 11
Joined: Sun Mar 12, 2023 10:17 pm
Contact:

Re: My settings gets overwritten by another mods

Post by Leoncio »

It worked when I put GearGirl as a dependency and then I added the code to the data.lua:

Code: Select all

if settings.startup["vanilla-flashlight"].value then
    data.raw["character"]["character"]["light"] = off
else
    data.raw.character["GearGirl-skin"].light = off
end
Edit:
Thank you for the help! :D

Leoncio
Burner Inserter
Burner Inserter
Posts: 11
Joined: Sun Mar 12, 2023 10:17 pm
Contact:

Re: My settings gets overwritten by another mods

Post by Leoncio »

Just tested the code again, without the Gear Girl Character mod, and it the game crashed saying that it couldn't find ["GearGirl-skin"].
Guess I still need some help figuring out how I can implement the settings...

Pi-C
Smart Inserter
Smart Inserter
Posts: 1659
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: My settings gets overwritten by another mods

Post by Pi-C »

Leoncio wrote:
Thu Apr 06, 2023 1:36 pm
Just tested the code again, without the Gear Girl Character mod, and it the game crashed saying that it couldn't find ["GearGirl-skin"].
Guess I still need some help figuring out how I can implement the settings...
You had an optional dependency on that mod! This means that Gear Girl is not required for your mod to run, but IF Gear Girl is active, it will be loaded before your mod. So you should make sure that the new character really exists before you attempt to change it:

Code: Select all

if settings.startup["vanilla-flashlight"].value then
    data.raw["character"]["character"]["light"] = off
else
    data.raw.character["GearGirl-skin"].light = off
end
The logic seems strange: If the value of your setting is true, you delete data.raw.character.character.light. (You never define the variable "off", so it is nil. Assigning nil to a table will delete it.) But if the value of your setting is false, you change the other character? I think this would make more sense:

Code: Select all

if settings.startup["vanilla-flashlight"].value then
    data.raw["character"]["character"]["light"] = off
    if data.raw.character["GearGirl-skin"] then
        data.raw.character["GearGirl-skin"].light = off
    end
end
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

Leoncio
Burner Inserter
Burner Inserter
Posts: 11
Joined: Sun Mar 12, 2023 10:17 pm
Contact:

Re: My settings gets overwritten by another mods

Post by Leoncio »

That did the trick! Tried so many different ways to get the "if settings.startup["vanilla-flashlight"].value" to work, thank you again for the help I would have never come up with the solution by myself! :D <3

FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2658
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: My settings gets overwritten by another mods

Post by FuryoftheStars »

Just as a side note, if it were an issue of the setting itself being overridden (and I'd advise doing this anyway), you can give your setting a unique name by including your mod name in it.

Example:

Code: Select all

data:extend({
    {
        type = "bool-setting",
        name = "yourmodname_vanillaflashlight",
        setting_type = "startup",
        default_value = false,
        order = "j"
    },
})
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles | New Gear Girl & HR Graphics

Post Reply

Return to “Modding help”