Krastorio 2


An overhaul mod focusing on end-game technologies and moderately increased complexity.

Overhaul
6 months ago
0.18 - 1.1
306K
Transportation Logistics Trains Combat Armor Mining Fluids Logistic network Manufacturing Power Storage

b nil access errors from krastorio.recipes.normalEnergyRequired(recipe_name)

4 years ago

Discord friend asked me for help with this error message:

https://drive.google.com/open?id=1SduY7zUu7mXRMGjkPeOQqro_4KG0IWyO

If it doesn't load, normalEnergyRequired() tried to access the normal difficulty when it didn't exist. Had the person add a nil check. The same error happened again on the line for expensive difficulty.

Referring to the prototype page on wiki, under "Recipe data":
https://wiki.factorio.com/Prototype/Recipe

energy_required is optional. If the recipe exists in the prototype with no energy_required, and no difficulties are defined, this is valid, but the function errors in this case.

Krastorio 2 was added before the start of a game.

Here's a link to a folder with the error image and the enabled mods:
https://drive.google.com/open?id=1TqhjNuPsDPos2q4522oTZ_8D0IxzIKOV

In the function, I don't know why the expensive recipe has a "seconds == 0.5" in front of it (it can't be anything else with how the function is).

My change to the function is here:
https://drive.google.com/open?id=1sHlr6Zo7AIq59uCBoZ3Nj7a8Yi-t3stJ

I also wanted to mention: technically, a difficulty can be nil, which then takes the other difficulty's energy required, but if the difficulty is false, the recipe can't be used in-game until a control effect sets it to enabled. I don't know how this function is used, but it may be relevant to Krastorio2 (should you always take the other energy_required, assuming it will be enabled somehow, or don't use the energy_required because the recipe is disabled at start?)

4 years ago

Forgot to add: I was going to have him log the recipes that the function was using. Simple log(recipe.name) before the if/thens to see which recipe caused the error. I ignored it because after the nil checks, the game loaded.

I could have him put the function back to "normal" so we can see which recipe caused the error.

Linver β˜†
4 years ago
(updated 4 years ago)

Thank u for ur report, I will solve this in the next update. I will find a solution on my own, I want keep function modular and with the same beheviour for not broke the mod.

Linver β˜†
4 years ago

Ps: seems that ur solution is equal with the way how I access in that field in the other functions, probably I forgot to do the same in that part of code (how u can see the library is not small, is easy do bit errors)