Accumulator buffer_capacity changes don't update on load

Place to post guides, observations, things related to modding that are not mods themselves.
Post Reply
d3x0r
Filter Inserter
Filter Inserter
Posts: 316
Joined: Sun Jun 04, 2017 8:56 am
Contact:

Accumulator buffer_capacity changes don't update on load

Post by d3x0r »

I've been tinkering with RailPowerSystem, which uses ghost accumulators in the tracks. I changed

Code: Select all

 data.raw["electric-energy-interface"]["rail-accu"].energy_source.buffer_capacity="2500kJ"; 
from buffer_capacity = "11kJ", and reloaded ( I changed it a lot ) and during on_tick event had this logging statement

Code: Select all

log( "required Power:".. requiredPower .. " ee:".. entity.energy.. " ga:".. ghostAccu.energy  .. " gbs:"..ghostAccu.electric_buffer_size);  
which shows the buffer capcity. No matter when/how I changed the buffer capacity, it would always print 11000. I had added a logging in data-final-updates.lua to see that the value was change, and it was... but still it said 110000. I searched for '11k', =11, a few other things and could not find any reason that the value was not updated.

Finally I decided to deconstruct the track and rebuild it, and then it got the updated values. So; changing buffer_capacity for an accumulator type object does not update what electric_buffer_size reports; or indeed that energy that it is able to store.

d3x0r
Filter Inserter
Filter Inserter
Posts: 316
Joined: Sun Jun 04, 2017 8:56 am
Contact:

Re: Accumulator buffer_capacity changes don't update on load

Post by d3x0r »

I was able to write a function to update all of these on configuration_update/on_init

Code: Select all

local function migrateAccumulators() 
	local surfaces = game.surfaces;--players[event.player_index]
	local i, j;
	for i=1,#surfaces do
		accums = surfaces[i].find_entities_filtered{ name="rail-accu" }
		for j=1, #accums do
			if( accums[j].electric_buffer_size ~= 25000 ) then
				accums[j].electric_buffer_size = 25000;
			end
		end
	end
end

Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: Accumulator buffer_capacity changes don't update on load

Post by Nexela »

d3x0r wrote:I was able to write a function to update all of these on configuration_update/on_init

Code: Select all

local function migrateAccumulators() 
	local surfaces = game.surfaces;--players[event.player_index]
	local i, j;
	for i=1,#surfaces do
		accums = surfaces[i].find_entities_filtered{ name="rail-accu" }
		for j=1, #accums do
			if( accums[j].electric_buffer_size ~= 25000 ) then
				accums[j].electric_buffer_size = 25000;
			end
		end
	end
end
Somethiing like this would be better handled in a migration.lua file instead of on_init and config

Also can be written a little more compact

Code: Select all

for _, surface in pairs(game.surfaces) do
  for _, accum in pairs(surface.find_entities_filtered{...} do
     if accum.electric_buffer_size ~= 25000 then
        accume.electric_buffer_sized = 25000

d3x0r
Filter Inserter
Filter Inserter
Posts: 316
Joined: Sun Jun 04, 2017 8:56 am
Contact:

Re: Accumulator buffer_capacity changes don't update on load

Post by d3x0r »

Nexela wrote:[quote="d3x0r"

Somethiing like this would be better handled in a migration.lua file instead of on_init and config

Also can be written a little more compact

Code: Select all

for _, surface in pairs(game.surfaces) do
  for _, accum in pairs(surface.find_entities_filtered{...} do
     if accum.electric_buffer_size ~= 25000 then
        accume.electric_buffer_sized = 25000
Ahh; probably true :)

Post Reply

Return to “Modding discussion”