Devilishness with a code

Place to get help with not working mods / modding interface.
Keysivi
Inserter
Inserter
Posts: 22
Joined: Mon Feb 07, 2022 5:29 pm
Contact:

Devilishness with a code

Post by Keysivi »

I have some kind of devilry going on with the code.

I'm trying to remove the unlocking of recipes in the game's technologies and other mods.

I use a special code for this. Example:

Code: Select all

	if data.raw.technology["explosive-rocketry"] then
		for i = 1, #data.raw.technology["explosive-rocketry"].effects do
			effect = data.raw.technology["explosive-rocketry"].effects[i]
			if effect.type == "unlock-recipe" and effect.recipe == "flamethrower-ammo" then
				index = i
			end
		end

		table.remove(data.raw.technology["explosive-rocketry"].effects, index)
	end
With vanilla technologies it works quite well... But with mods some devilry starts!!!

For example, in the chemical-rocket mod https://mods.factorio.com/mod/chemical-rocket/ it says:

Code: Select all

local technology = data.raw.technology["explosive-rocketry"]
table.insert(technology.effects, {type = "unlock-recipe", recipe = "chemical-rocket"})
table.insert(technology.effects, {type = "unlock-recipe", recipe = "incendiary-rocket"})
table.insert(technology.effects, {type = "unlock-recipe", recipe = "flamethrower-ammo"})
I'm trying to delete these recipes:

Code: Select all

if mods["chemical-rocket"] then

	if data.raw.technology["explosive-rocketry"] then
		for i = 1, #data.raw.technology["explosive-rocketry"].effects do
			effect = data.raw.technology["explosive-rocketry"].effects[i]
			if effect.type == "unlock-recipe" and effect.recipe == "chemical-rocket" then
				index = i
			end
		end

		table.remove(data.raw.technology["explosive-rocketry"].effects, index)
	end
	
	if data.raw.technology["explosive-rocketry"] then
		for i = 1, #data.raw.technology["explosive-rocketry"].effects do
			effect = data.raw.technology["explosive-rocketry"].effects[i]
			if effect.type == "unlock-recipe" and effect.recipe == "incendiary-rocket" then
				index = i
			end
		end

		table.remove(data.raw.technology["explosive-rocketry"].effects, index)
	end
	
	if data.raw.technology["explosive-rocketry"] then
		for i = 1, #data.raw.technology["explosive-rocketry"].effects do
			effect = data.raw.technology["explosive-rocketry"].effects[i]
			if effect.type == "unlock-recipe" and effect.recipe == "flamethrower-ammo" then
				index = i
			end
		end

		table.remove(data.raw.technology["explosive-rocketry"].effects, index)
	end
	

end
But instead of deleting them, recipe = "explosive-rocket" is deleted

What the hell?""""!!!!!!!
s6x
Burner Inserter
Burner Inserter
Posts: 12
Joined: Fri Nov 15, 2024 8:22 pm
Contact:

Re: Devilishness with a code

Post by s6x »

Are you using dependencies to make sure that your mod's code runs after the mods you want to modify?

That code you pasted will delete the last index it finds (whatever the value of i was) if it finds if it isn't able to match anything, and it won't find anything if the other mod's code hasn't run yet.
Keysivi
Inserter
Inserter
Posts: 22
Joined: Mon Feb 07, 2022 5:29 pm
Contact:

Re: Devilishness with a code

Post by Keysivi »

For sure!

Here is the code from info.json :

Code: Select all

{
  "name": "My_add_pack_updated",
  "version": "0.0.4",
  "factorio_version": "2.0",
  "title": "All kinds of things (updated)",
  "author": "KeySiVi",
  "description": "Mod where I plan to add my own developments and forks",
  "dependencies": [
	"? NapalmArtillery",
    "? chemical-rocket",
	"? atomic-artillery-reborn",
	"! flamethrower-fluid"
  ] 
}
Keysivi
Inserter
Inserter
Posts: 22
Joined: Mon Feb 07, 2022 5:29 pm
Contact:

Re: Devilishness with a code

Post by Keysivi »

This is the second mod with which such a hassle...

The first was flamethrower-fluid

There the technologies were written in such a way:

Code: Select all

for _,t in pairs(data.raw.technology) do
	for _,e in pairs(t.effects or {}) do
		if e.type == "unlock-recipe" then
			if e.recipe == "flamethrower-ammo" then
				table.insert(t.effects,{type = "unlock-recipe",recipe = "flamethrower-fuel"})
				table.insert(t.effects,{type = "unlock-recipe",recipe = "improved-flamethrower-ammo"})
			end
		end
	end
end
I suffered and suffered with it, and then simply copied it into my mod...
s6x
Burner Inserter
Burner Inserter
Posts: 12
Joined: Fri Nov 15, 2024 8:22 pm
Contact:

Re: Devilishness with a code

Post by s6x »

Ok, you're doing this in data.lua, right?

The issue is similar to dependencies, but a little bit trickier. I took a look at chemical-rockets and I noticed it adds its recipes in data-updates.lua. So if your code is in data.lua, then it's ultimately the same problem; chemical-rockets hasn't run its code yet so your code won't see the recipes added. This may be why some mods cause you problems and others don't.
Post Reply

Return to “Modding help”