Page 1 of 1

Iterate over and change techs?

Posted: Tue Jul 28, 2015 10:57 am
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

Re: Iterate over and change techs?

Posted: Tue Jul 28, 2015 11:05 am
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

Re: Iterate over and change techs?

Posted: Tue Jul 28, 2015 11:21 am
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.

Re: Iterate over and change techs?

Posted: Tue Jul 28, 2015 12:01 pm
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