Page 1 of 1

Migration Script not working

Posted: Sun May 21, 2017 3:48 pm
by Ranakastrasz

Code: Select all

for i, player in ipairs(game.players) do
    player.force.reset_recipes()
    player.force.reset_technologies()
    
    player.force.recipes["flame-shotgun-shell"].enabled = player.force.technologies["military-4"].researched
    
    player.force.recipes["uranium-cannon-shell"].enabled = false
    
    player.force.recipes["atomic-rocket"].enabled = player.force.technologies["atomic-bomb"].researched
    
    
    if (player.force.technologies["flamethrower"].researched) then
        player.force.recipes["flamethrower-ammo-crude"].enabled = true
        player.force.recipes["flamethrower-ammo-petrol"].enabled = true
        
    end
    
    
end
Is there anything obviously wrong here?
The only part of this that works is the flamethrower-ammo-petrol part, the rest seems to do nothing.
I am certain I have the recipe names correct, and the tech names. I cannot understand what exactly is going on here.

Re: Migration Script not working

Posted: Sun May 21, 2017 9:35 pm
by Nexela
http://lua-api.factorio.com/latest/LuaCustomTable.html

ipairs does't work on custom tables

Additionally you could iterate forces directly instead of every player

Code: Select all

for _, force in pairs(game.forces) do
    force.recipes["flame-shotgun-shell"].enabled = force.technologies["military-4"].researched
    
    force.recipes["uranium-cannon-shell"].enabled = false
    
   force.recipes["atomic-rocket"].enabled = force.technologies["atomic-bomb"].researched
    
    
    if (force.technologies["flamethrower"].researched) then
       force.recipes["flamethrower-ammo-crude"].enabled = true
        force.recipes["flamethrower-ammo-petrol"].enabled = true
        
    end
end

Re: Migration Script not working

Posted: Sun May 21, 2017 9:51 pm
by Ranakastrasz
Huh. Never had trouble with ipairs for prototypes before, but Ok.

Also, yea, that makes sense.

Thanks for help, hopefully it will work when I have a chance to test it.