How do I activate some code once technology is researched?

Place to get help with not working mods / modding interface.
Post Reply
ManselD
Inserter
Inserter
Posts: 26
Joined: Mon Apr 01, 2013 10:43 pm
Contact:

How do I activate some code once technology is researched?

Post by ManselD »

So far I have this:

Code: Select all

data:extend({
    {
        type="technology"
	    name="Mass_Production"
	    icon="__Mansels_Tech_Mod__/graphics/technology/Mass_Production.png"
		prerequisites={
		    "logistics"
		},
		effects={
		
		},
		unit={
		    count=30,
		    ingredients ={
		        {"science-pack-1", 1},
		        {"science-pack-2", 1}
		    },
		    time=15
		}
    }
})
Now, how would I go about doing something like this after it is researched?:

Code: Select all

data.raw.ammo["piercing-bullet-magazine"].magazine_size = 20

User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: How do I activate some code once technology is researche

Post by FreeER »

First why not use type = "ammo-damage" or type = "gun-speed" (other than that it doesn't truly match your technology lol)
Now to your question, I'm not sure if this is possible I tried

Code: Select all

if tostring(game.player.force.technologies["iron-working"].researched) == true then data.raw.ammo["piercing-bullet-magazine"].magazine_size = 20 end
but that doesn't change the loaded data and I don't think it would be persistent accross a save game (as in after researching save/load for it to take effect)

That's the best I could think of at the time (though I tried changing it from data.raw.ammo to data.ammo and ammo, just to see if one of those would be able to change it ingame lol)


P.S. hey devs, I tried adding this to iron working effects for testing

Code: Select all

      {        data.raw.ammo["piercing-bullet-magazine"].magazine_size = 20      }
and received:

Code: Select all

content title
Error in assignID, 'robotics' was not recognized id of technology
This was not the error I was expecting (though I was expecting an error)
<I'm really not active any more so these may not be up to date>
~FreeER=Factorio Modding
- Factorio Wiki
- My Factorio Modding Guide
- Wiki Modding Guide
Feel free to pm me :)
Or drop into #factorio on irc.esper.net

kovarex
Factorio Staff
Factorio Staff
Posts: 8078
Joined: Wed Feb 06, 2013 12:00 am
Contact:

Re: How do I activate some code once technology is researche

Post by kovarex »

This is not possible.

I would like to explain this subject in more detail (and to let you peak what kind of problems we need to think about daily)

a) Access to read/change the prototype data is only in the prototype loading phase of the game (when game is started).
b) We could make way to change the prototype specification in the game, but this wouldn't be good way to do it because this way, you would change the magazine_size for all forces (players) at the same time, but you would like to change it only for the player that discovered the technology.

Good example are recipes.

There is one central set of recipes specification, you specify these in the starting script.
Once the game starts, every player (force) takes this set of recipes, and makes its own a copy of these.
When you change anything in the game, you change the recipe copy of some force

Code: Select all

game.player.force.recipes["smart-inserter"].enable()
So the second player might still have disabled the recipe (the same will apply once we allow to change other recipe parameters), so every player can have different version.

This is the reason, that when you change the definition of recipe, and load old savegame, it won't be affected, if you want the recipe to affect old games as well, you need to do what we did in the migration script:

Code: Select all

local forcelist = game.forces
for index, item in pairs(forcelist) do
  local recipes = item.recipes
  recipes["wall"].enable()
  recipes["wall"].reload() -- Forces to copy the global wall recipe to player
end
Obviously, we can't reload all recipes automatically, as the player would loose any individual changes of the recipe he gained during the game.


So, if we wanted to change the magazine size, there are 2 ways to do it.
a) Make some kind of copy of items specification to every force (player) so two players using the same magazine could use it differently (it would have different properties for them)
b) Make the magazine size specification part of the item (not prototype), so once you create the better magazine, everyone who uses it would see having it 20 bullets (this makes more sense),
this would need some kind of specification for every player of how should his assembled items be affected. This introduces problems of, how would these magazines be stacked (probably couldn't be stacked).

Post Reply

Return to “Modding help”