Tral's Robot Tree Farm


Robots can plant and harvest tree seeds.

Content
3 years ago
1.0 - 1.1
4.28K
Environment

b 【✔️】 Wrong version check for 1.0

3 years ago
(updated 3 years ago)

Hi! I've just got a bug report for Bio Industries when your mod is installed. Trying to reproduce the bug with Factorio 1.0.0, I found that Factorio will crash on starting:

   0.000 2020-12-27 19:43:23; Factorio 1.0.0 (build 54889, linux64, alpha)
   …
   8.783 Factorio initialised
   8.792 Mods to disable:Failed to load mods: Error in assignID: item with name 'raw-wood' does not exist.

Source: rtf-bio-tree-tree-01-1-6 (tree).

Mods to be disabled:
• Tral_robot_tree_farm (1.0.5)

There is no item "raw-wood" in Factorio 1.0, that's still a remnant from 0.16. You have this in data-final-fixes.lua (lines 61ff.):

local wood_name = "raw-wood"
-- local dugup_frames = 4
local game_version = 0.16
local mining_time = 2
if (string.sub(mods["base"], 1, 4) == "0.18") or (string.sub(mods["base"], 1, 4) == "1.0") then
    wood_name = "wood"

mods["base"] is "1.0.0", so string.sub(mods["base"], 1, 4) is "1.0." and the test must fail. Would you mind fixing this, please? Just remove the version check and the code for Factorio <0.18 -- it's not needed anymore because such old versions won't run anyway with 1.0.

In case you wonder why I'm concerned about bugs in such an old version although you've already updated the mod for Factorio 1.1: I've found that it's worthwhile to support the stable version as long as people are using it (for example, players on Steam won't get 1.1 automatically). I've already made double releases for BI when Factorio 0.17 still was the stable version, and I continue that now where Factorio 0.18/1.0 is stable. If you care to take a peek at the download numbers, you'll notice that about 60% of the downloads still are for the stable versions (0.18.30/0.18.31 vs. 1.1.0/1.1.1). For me, that's reason enough to make sure my mods are backwards compatible whenever it makes sense. :-)

3 years ago
(updated 3 years ago)

Hi, thank you for the tip.
All this mod is a work in progress, it has a lot of old bugs and old stuff.
I don't have much time at the moment, but I will try and fix it now.

And for the pre 0.18 stuff: I will remove all of that as soon as I have some time.

3 years ago
(updated 3 years ago)

Thanks, this seems to work now! And take your time for the other stuff. :-)

But there's something else. It seems our code for tree growing has the same roots (OwnlyMe). In BI, we create variations of existing trees with the name pattern "bi-tree-TREENAME-x" (x = 1…4) while you use "rtf-TREENAME-x" (default: x = 1…20). With both mods active, I now find tree names like "rtf-bio-tree-tree-01-1-5" in my log because first BI created a variation of the vanilla "tree-01", and then your mod created another variation of mine. So for each tree known to the game, your mod will create up to 800 variations unnecessarily (your settings allow for 3…200 stages) -- and if mods like Alien Biomes are used, that will be a lot of new tree prototypes! I guess we should both blacklist the trees from each other's mods, so we can minimize the impact.

3 years ago

Yep, that wouldn't be good.
I will blacklist them soon.
💪💪

3 years ago

No need to hurry! For now, I'll remove all "rtf-bio-tree-TREENAME-x-y" prototypes in data-final-fixes.lua (1200 prototypes with just the vanilla trees, by the way).

3 years ago

Just uploaded the new version …

By the way, this happens when both OwnlyMe's Robot Tree Farm and your mod are active:

5.491 Error ModManager.cpp:1514: Failed to load mod "Tral_robot_tree_farm": __Tral_robot_tree_farm__/data-final-fixes.lua:450:       attempt to perform arithmetic on field 'amount' (a nil value)
stack traceback:
        __Tral_robot_tree_farm__/data-final-fixes.lua:450: in function 'make_minable_results'
        __Tral_robot_tree_farm__/data-final-fixes.lua:529: in main chunk

You'd better add a conflict with the original RTF mod to the 1.0 version.

Have a happy new year! :-)

3 years ago

Thank you!!

Happy new year!!
🎉🎆🥳🥳🎆🥳

3 years ago

Hi, the problem is fixed (>=1.2.8)

And i wanted to ask you a question about what mods can do.
Is it possible for a mod to create a table and allow other mods to put data in that table?
(in the loading stages, not in control)

3 years ago

Hi, the problem is fixed (>=1.2.8)

Thanks! I'll check it out and report back later. :-)

And i wanted to ask you a question about what mods can do.
Is it possible for a mod to create a table and allow other mods to put data in that table?

Sure., that's an established method for mod interaction during the data stage. For example, Assembler Pipe Passthrough provides a table where other mods can enter entities they want to excempt. So, in BI, I do this in data-updates.lua:

-- Blacklist bioreactor in Assembler Pipe Passthrough
if mods["assembler-pipe-passthrough"] then
  appmod.blacklist['bi-bio-reactor'] = true
end

All you need to do is declare a global table in data.lua. You should keep in mind that "global" really means "global" here -- unlike in the control stage, where each mod has its own global table, global variables/tables can be accessed by all active mods. So you should make sure you use a unique name for your table, that somehow refers to your mod (like "appmod", where "app" is short for "assembler pipe passthrough").

You could even make it that all mods can write to the table in data.lua even if they are loaded before your mod. You would put something like this at the top of your data.lua:

-- Create a global table where other mods can enter trees you want to ignore
-- unless it already has been populated by other mods
TRTF_ignore = TRTF_ignore or {}

-- List of entities that you always want to ignore
local always_ignore = { "prototype_a", "prototype_b", "prototype_c"}
for k, v in ipairs(always_ignore) do
  TRTF_ignore[#TRTF_ignore + 1] = v
end

Other mod would add this to their data.lua:

if mods["Tral_robot_tree_farm"] then
  -- Create or add to TRTF ignore list
  TRTF_ignore = TRTF_ignore or {}
  for k, v in ipairs({ ignore_a.name, ignore_b.name }) do
table.insert(TRTF_ignore, v)
  end
end

In data-updates.lua or data-final-fixes.lua, you can then use these data:

local ignore
for tree_name, tree in pairs(data.raw.tree) do
  ignore = false
  for n, name in ipairs(TRTF_ignore) do
if tree_name == name then
  ignore = true
  break
end
  end
  if not ignore then
-- Do stuff
  end
end

Sometimes it may be easier to convert the ignore list to a dictionary before using it:

local ignore = {}
for k, v in ipairs(TRTF_ignore) do
  ignore[v] = true
end

for tree_name, tree in pairs(data.raw.tree) do
  if not ignore[tree_name] then
-- Do stuff
  end
end
3 years ago

Thank you so much!

My idea was to make this mod more like a library to grow trees
allowing customization by other mods to the properties, as the seed icon, growth steps, total time of growth and anything that will come to mind.
Then it would be a lot easier to do everything.

3 years ago

My idea was to make this mod more like a library to grow trees
allowing customization by other mods to the properties, as the seed icon, growth steps, total time of growth and anything that will come to mind.

Seems you're looking for trouble! :-) You already have settings to allow users to adjust things (grow steps etc.), now you also want that mods can change these. What will take precedence? Will the user setting be the top limit? What if the user setting calls for 20 grow stages, but a mod requests just 3? This could make some trees overpowered (giving the full amount of wood after just 3 stages, while other trees take much longer to grow).

Technically, it would be possible to pass on the necessary data and make the list a dictionary right from the start:

local tree_settings = {
  ["prototype_a"] = { grow_stages = 4, total_grow_time = x, …},
  ["prototype_b"] = { grow_stages = 7, total_grow_time = y, …},
  ["prototype_a"] = { grow_stages = 2, total_grow_time = z, …},
}
for k, v in pairs(tree_settings) do
  TRTF[k] = v
end

But you should plan ahead and consider very well what data you will need -- and document this carefully so that other modders know exactly what you need. (Once you release that library, changes to the data structure may cause problems for other mods.) Also, you still should give other modders the chance to blacklist their trees completely. That would be useful for other mods that have their own growing-tree prototypes, or that use trees for something entirely different. (For example, in Water Turrets, I spawn a defender bot whenever a fire is created so my turrets can "attack fire", or we create dummy characters to place in cars etc. in Autodrive and AAI Programmable Vehicles. So a tree may not always be a tree.) Finally, you'll need to take care that you provide sane fallback values if a mod doesn't give you all the data you need. It's so easy to let the game crash if you just assume that you'll get valid data. :-)

3 years ago

That was the plan, but as you said I need to look more into it.
Maybe in the future I will put it into practice.

And thank you again!! It's nice to get tips from someone more experienced 💖

New response