Edit Technology Price Multiplier


Allows you to change the price multiplier for technologies in the game even after the game has started. The value can be changed in the mod settings in the 'per map' section.

Utilities
a month ago
2.0 - 2.1
53
Environment

g Crash in on_init ("Value is invalid") when the map's technology price multiplier is above 1000

a month ago

Hi, thanks for the mod! Adding it to an existing map that was created with a technology price multiplier of 10000 crashes on load:

Error while running event Technology_Price_Multiplier::on_init()
Value is invalid.
stack traceback:
    [C]: in function '__newindex'
    __Technology_Price_Multiplier__/control.lua:10: in function <__Technology_Price_Multiplier__/control.lua:8>

Versions: mod 1.0.1, Factorio 2.1.24, no other mods involved (reproduced with base only).

Steps to reproduce
1. Create a new map with the research price multiplier set to 10000 (any value > 1000).
2. Save, enable the mod, load the save → crash in on_init().

Cause
copy_map_value_into_setting() writes the map value into the runtime-global setting, but the setting is defined with maximum_value = 1000. Factorio rejects any value outside the setting's min/max with "Value is invalid". The engine itself allows technology_price_multiplier in the range [0.001, 100000] (runtime API docs, DifficultySettings), so maps above 1000 can't use the mod at all.

Suggested fix (raise the maximum to the engine range and clamp the copied value as a safeguard):

--- a/settings.lua
+++ b/settings.lua
@@ -5,7 +5,8 @@ data:extend({
         setting_type = "runtime-global",
         default_value = 1,
         minimum_value = 0.001,
-        maximum_value = 1000,
+        -- Same range the engine accepts for DifficultySettings::technology_price_multiplier.
+        maximum_value = 100000,
         order = "a"
     }
 })
--- a/control.lua
+++ b/control.lua
@@ -1,13 +1,20 @@
 local setting_name = "Technology_Price_Multiplier-value"
 local copying_from_map = false

+-- Range of DifficultySettings::technology_price_multiplier (and of the setting).
+local min_value = 0.001
+local max_value = 100000
+
 local function apply_multiplier()
     game.difficulty_settings.technology_price_multiplier = settings.global[setting_name].value
 end

 local function copy_map_value_into_setting()
+    local value = game.difficulty_settings.technology_price_multiplier
+    -- Writing a value outside the setting's min/max raises "Value is invalid".
+    value = math.max(min_value, math.min(max_value, value))
     copying_from_map = true
-    settings.global[setting_name] = {value = game.difficulty_settings.technology_price_multiplier}
+    settings.global[setting_name] = {value = value}
     copying_from_map = false
 end

--- a/locale/en/locale.cfg
+++ b/locale/en/locale.cfg
@@ -2,4 +2,4 @@
 [mod-setting-description]
-Technology_Price_Multiplier-value=Research cost multiplier for this map. A new map starts at the value from map generation. Resetting this setting returns it to 1. Allowed range is 0.001 to 1000.
+Technology_Price_Multiplier-value=Research cost multiplier for this map. A new map starts at the value from map generation. Resetting this setting returns it to 1. Allowed range is 0.001 to 100000.

Tested (headless, Factorio 2.1.24, save created with multiplier 10000):
- 1.0.1: crashes in on_init() as above.
- Patched: loads fine, the setting picks up 10000; changing the setting to 500 sets game.difficulty_settings.technology_price_multiplier to 500.

I couldn't find a public repository for the mod, otherwise I would have opened a pull request. Happy to send the patched files if that helps.

a month ago

Oh apparently, they have changed the minimum and maximum range of this property since 2.0.
I did not know that I will fix that right away. Thanks for letting me know.

a month ago

Yeah, the crash happened because on starting a new map with the mod (and when adding it later), I added events that set the setting to the actual value from the map gen settings. Otherwise, every game would have the same default setting of 1, even though you set it to something else in the map settings, and it would only change after tweaking the setting.

I thought that was unintuitive, so I copy the value first thing after game start/mod adding. But the setting is hard-limited to the old range of 0.001-1000, and that caused the crash if your map settings value was higher than the allowed range.

a month ago

Update is out!
thx again!

New response