Page 1 of 1

Accumulator buffer_capacity changes don't update on load

Posted: Thu Jul 20, 2017 7:57 pm
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.

Re: Accumulator buffer_capacity changes don't update on load

Posted: Sun Jul 23, 2017 6:44 pm
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

Re: Accumulator buffer_capacity changes don't update on load

Posted: Sun Jul 23, 2017 9:51 pm
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

Re: Accumulator buffer_capacity changes don't update on load

Posted: Sun Jul 23, 2017 10:45 pm
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 :)