Treeees


Let the trees on your map spread over time similar to real vegetation

Content
3 years ago
0.17 - 1.1
13.4K
Environment

b [done] Crash with Tral's Robot Tree Farm

4 years ago
(updated 4 years ago)

Hi! If both your mod and Tral's Robot Tree Farm are active, the game will crash on startup with the following error:

     2.533 Script @__Trees__/data-final-fixes.lua:27: rtf-tree-01-1: rtf-tree-01-1
     2.534 Error ModManager.cpp:1555: Failed to load mod "Trees": __Trees__/data-final-fixes.lua:9: attempt to index local 's' (a nil value)
   stack traceback:
      __Trees__/data-final-fixes.lua:9: in function 'is_vertical'
         __Trees__/data-final-fixes.lua:17: in function 'get_lying_tree_indexes'
      __Trees__/data-final-fixes.lua:28: in main chunk

I've added a line to log the tree names before this line:

tree.order = encode(get_lying_tree_indexes(tree))

so the last line in the stacktrace is off by 1. Anyways, it seems that trees from Robot Tree Farm don't have the trunk.shift property, while you assume in the function is_vertical(w,h,s) that all arguments will always be present.

Another thing: I'm the maintainer of Bio Industries, and just reworked our tree-growing code. We create variations of each tree prototype, and when a sapling is planted manually or by a terraformer, it will grow through up to 4 stages before it becomes a fully grown tree. During the first 3 stages, mining a tree will yield a sapling (probability increasing with each stage); in stage 4, mining a tree will yield 1 wood. I'm afraid there could be problems if both BI and your mod try to "grow" or "age" these trees. Would you mind blacklisting the trees from BI? You could use this code to compile a list of our prototypes:

local ignore_trees = {}
for name, tree in pairs(game.get_filtered_entity_prototypes({{filter = "type", type = "tree"}} or {}) do
  if string.match(name, "^bio%-tree%-.+%-%d$") then
    ignore_trees[name] = true
  end
end
…
if not ignore_trees[name] then
  -- Insert your magic here!
end

If you can think of anything I should do on my end to prevent problems, please don't hesitate to ask!

4 years ago

Thanks for the feedback!

I fixed the bug in 4.1.2 and changed the code to progress only trees with autoplace specification (using {filter = 'autoplace'}).
This shouldn't touch your trees anymore, i hope ;P

Mind if you could verify that it works?

4 years ago
(updated 4 years ago)

Hi! Sorry for the delay …

I fixed the bug in 4.1.2

One of them. Turns out that the other variables also make problems, and it's with "rtf-tree-01-1" again. I'm not really familiar with the tree prototypes, but apparently there are different ways to define them and you didn't allow for all of them. See the wiki:

variations
Type: table of TreePrototypeVariation
Array. Can't be empty. Either this or pictures must exist.

So, it's not guaranteed that tree.variations will exist, it could also be tree.pictures (which is an array of sprites). Even if there are tree.variations, size, width, and height may be hidden within different layers.

I've inserted the following right before line 9 (where is_vertical is called):

if not (w and h) then
  log(prototype.name .. ": w=" .. tostring(w) .. ", h=" .. tostring(h) .. "\ttrunk: " .. serpent.block(trunk))
end

If you run this, you'll see that the the tree causing the crash has its trunk variations defined as layers, so height and width are not set where you expect to find them and will be nil. Too bad, I thought I could steal your code for identifying lying trees! :-)

By the way, I just checked the BI code: We don't seem to look for layers, we look for properties at the top layer and provide hard-coded fallback values if these properties are nil, e.g.:

for var_id, variation in pairs(tree.variations) do
  variation.trunk.scale = (variation.trunk.scale or 1) * i / TREE_LEVELS
 …
end

and changed the code to progress only trees with autoplace specification (using {filter = 'autoplace'}).
This shouldn't touch your trees anymore, i hope ;P

Mind if you could verify that it works?

I haven't tested too much yet (simplified the code some more, and still find syntax errors or variables that shouldn't be used anymore). But we explicitly set tree.autoplace = nil, so as far as I can see they should be ignored in the control stage.

4 years ago

Oh you are right! Forgot about the layers and pictures :p
Should be fixed in version 4.1.3, at least it's not crashing any more when loading with Tral's Robot Tree Farm.

Not sure if i nailed the variation counting for pictures, documentation is more than vague on variation_count.

New response