kyranf / robotarmyfactorio

A mod to add robot troop units and perhaps associated support buildings and items to produce and control them.
MIT License
35 stars 12 forks source link

Error while applying migration #125

Closed TankFox closed 6 years ago

TankFox commented 6 years ago

After installing robot army 0.3.4, trying to load up my existing map fails with;

Error while applying migration: Robot Army: robotarmy_0.2.1.lua

robotarmy/migrations/robotarmy_0.2.1.lua:21: attempt to index field 'rally-beacon' (a nil value)

kyranf commented 6 years ago

hm.. can you test for me quickly just deleting all the migration scripts? kind of weird that going from 0.3.3 to 0.3.4 would even trigger those scripts.. sorry about that. I didn't test every scenario like loading from a 0.3.3 game after upgrading to 0.3.4.

so that means unzipping the zip file to just be the folder, and then going into Migrations folder and deleting all the scripts in there.

kyranf commented 6 years ago

I just loaded up a test game i had on 0.15.37 with robot army 0.3.3 with the new 0.16.4 and robot army 0.3.4 and it didn't try to apply the migration scripts for me... what version of factorio and robot army did you have again??

TankFox commented 6 years ago

I will see if I can figure out how to delete the migration script, but this is a brand new map that did not previously have robot army installed in any way.

when the new Factorio 1.16 came out I began a new map, and Robot Army was not enabled at all until you brought it up to date for 1.16. I think the issue is that the migration script is looking for something to migrate and not finding anything.

TankFox commented 6 years ago

Yes, deleting the migration folder entirely allowed me to load my map!

To reiterate, I created this map after 1.16 came out but before Robot Army updated, and could not load the map due to the above error.

The map had never seen Robot Army before

georgehank commented 6 years ago

Same here, had the same error on a new 0.16-only install, so a new map that gains mods as they get updated to .16 and thus become available.

Which really is weird, since it then absolutely positively should trigger any migration scripts.

kyranf commented 6 years ago

migration scripts i thought were only meant to fire if the mod version is detected as updating, and it only runs certain scripts.

the reason why that migration script failed is because the rally point entity has been removed from the mod, but back in 0.2.1 or whatever the migration script is trying to run for, the mod had that entity..

Some of those migration scripts are sure to break things now, or reference things not in the mod anymore, I think I might clean out all the migration scripts and only put new ones in as required for that release only.

kyranf commented 6 years ago

Weird I just made a game without robot army enabled, saved it, went back and enabled robot army again and loaded up the save. No migration scripts tried to be applied? I can't reproduce this issue :(

kyranf commented 6 years ago

This could be a factorio bug where if a mod is first loaded, it just runs all the migration scripts anyway (which it shouldn't)

kyranf commented 6 years ago

yes make a 2nd issue please

kyranf commented 6 years ago

I worked out while I was trying to reproduce the issue i didn't successfully re-enable my mod. I got it to throw the error loading the mod for the first time into a 0.16 save game that was started without the mod. i will submit a bug report on the forums

Astree13 commented 6 years ago

same bug here : started a new 0.16 game, and tried to load the mod after starting the game, got the migration error. If I load the mod "before" creating a new game, it works fine. So the problem seams to be while loading the mod on an existing map.

Hiestaa commented 6 years ago

I'm no author of this mod, so take my comment with a grain of salt.

I faced the same issue migrating a map from Factorio 0.16.16 without robotarmy mod to Factorio 0.16.16 with the mod enabled.

I tried to get my hand dirty and un-zipped the mod to take a peak at the code that is erroring out, for the record it's the following lua instruction

for i, force in pairs(game.forces) do 
  -- [...]
  if force.technologies["military"].researched then
    -- [...]
    force.recipes["rally-beacon"].enabled=true

Thanks for great work 💟

kyranf commented 6 years ago

The quick and easy fix is to delete the entire migrations folder. turns out this behaviour is not a bug, supposedly every single migration leading up to the current version will be run in sequence if you add the mod fresh to an existing save game for the first time. It's illogical if you ask me, but that's what is causing this error right now.

I have removed the rally flag stuff from the mod, to declutter it and I don't intend on bringing it back anymore. It's a shame that it broke the mod like this, I bet hundreds of people have encountered the issue by now, I hope they see what is required by reading here..

I will release a new version which has the migrations removed for the users, plus a few minor additional things.

OvermindDL1 commented 6 years ago

Yeah I just hit it myself on a scenario map as well.

kyranf commented 6 years ago

Fixed in current version