Running TechnologyUnit::count_formula in data stage

Place to get help with not working mods / modding interface.
Post Reply
Pi-C
Smart Inserter
Smart Inserter
Posts: 1654
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Running TechnologyUnit::count_formula in data stage

Post by Pi-C »

I know that it is possible to calculate a value using TechnologyUnit::count_formula at runtime, using game.evaluate_expression. But is it also possible to use the formula in data stage?

Use case: My mod adds technologies that have vanilla and/or modded technologies as prerequisites. Setting the TechnologyUnit of my techs to a fixed value doesn't really make sense because other mods could modify the prerequisite techs after I've generated the techs in data.lua. So I had the idea to add TechnologyUnit in data-final-fixes by picking the most expensive prerequisite and using its ingredients (increasing the count a bit). That's trivial if the prerequisite uses unit.count, but it's hard to compare unit.count and unit.count_formula, or unit.count_formula and unit.count_formula unless it would be possible to run the formula with some value.

I hope there is a way to do this! Writing a parser that takes the count_formula from a string and translates it into executable math operations would certainly be an interesting task, but I'm afraid it may be a tiny bit too excessive for this rather marginal feature of my mod. :mrgreen:
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

Post Reply

Return to “Modding help”