Iterate over and change techs?

Place to get help with not working mods / modding interface.
Post Reply
ArgTang
Burner Inserter
Burner Inserter
Posts: 10
Joined: Tue Jul 28, 2015 10:52 am
Contact:

Iterate over and change techs?

Post by ArgTang »

Is there a way to iterate over techs and change them?
or do i have to copy techfile and change that file via some script? something like this: https://gist.github.com/pfmoore/aa101ee1daeebf202e87

I have tried some diffrent things ex:

Code: Select all

for n,t in pairs(game.players) do
    for v, techs in pairs(t.force.technologies) do
        techs.unit.time = techs.unit.time * 10
    end
end

Choumiko
Smart Inserter
Smart Inserter
Posts: 1352
Joined: Fri Mar 21, 2014 10:51 pm
Contact:

Re: Iterate over and change techs?

Post by Choumiko »

You're gonna want to do it in data-updates.lua (or even data-final-fixes.lua)

Code: Select all

for i, tech in pairs(data.raw["technology"]) do
  tech.unit.time = tech.unit.time * 10
end
To make it work in an existing save you will probably need a migration file (not sure about that):

Code: Select all

for _, force in pairs(game.forces) do
  force.reset_recipes()
  force.reset_technologies()
end

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

Re: Iterate over and change techs?

Post by orzelek »

I'm attaching a mod that should give you some ideas :D
(It's not mine - I did only convert it to 0.12 so credits go to original author).

Looking at what you want to do this mod might be doing it already.
Attachments
ScienceCostTweaker_0.0.2.zip
(1.56 KiB) Downloaded 81 times

ArgTang
Burner Inserter
Burner Inserter
Posts: 10
Joined: Tue Jul 28, 2015 10:52 am
Contact:

Re: Iterate over and change techs?

Post by ArgTang »

thanks!

in data-updates.lua i now have:

Code: Select all

	for i, tech in pairs(data.raw["technology"]) do
	
		local level = 1 + (#tech.unit.ingredients/10)*2;
  		tech.unit.count = tech.unit.count * level
		tech.unit.time = tech.unit.time * level
	end		
reset_recipes wont work in this file, but should probably be in control.lua anyway

now i have to playtest

Post Reply

Return to “Modding help”