Renewal


Gives more life to your world by allowing trees to grow and spread.

7 years ago
0.13
6

b LuaTile can be invalid

7 years ago

I recevied the following error message after letting the mod run for a little while on a new world:

Error while running event on_tick(ID 0)
LuaTile API call when LuaTile was invalid.
stack traceback:
renewal/control.lua:127:in function
'handle jobs'
renewal/control.lua:21:in function
<renewal/control.lua:12>

I looked at the location of the error and came to the conclusion that surface.get_tile can return a nil value (my guess is trying to pull a tile from a chunk that has not be generated)

To get around this, I changed the code to put the result of get_tile into a local and tested it for nil before trying to access its name.

-- Grab the per-tile propogation chance
local positionTile = surface.get_tile(position[1], position[2])
local propagation_chance = nil
if positionTile ~= nil then
propagation_chance = a_type.propagation_chance[positionTile.name]
else
propagation_chance = 0
end

Hopefully this is helpful to you.

7 years ago

Apparently this is wrong, I received the same error again even with this altered code after letting it run for a bit.

7 years ago

I looked up the Factorio API and found that LuaTile can be invalid due to other effects within the engine. So you just need to put a check on the valid property before you try to use the tile.

-- Grab the per-tile propogation chance
local positionTile = surface.get_tile(position[1], position[2])
local propagation_chance = nil

if positionTile ~= nil then
if positionTile.valid == true then
propagation_chance = a_type.propagation_chance[positionTile.name]
else
propagation_chance = 0
end
else
propagation_chance = 0
end

7 years ago

Thank you! I'll implement this in the next patch

New response