Migration Script not working

Place to get help with not working mods / modding interface.
User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 2179
Joined: Thu Jun 12, 2014 3:05 am
Contact:

Migration Script not working

Post 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.
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: Migration Script not working

Post 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
User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 2179
Joined: Thu Jun 12, 2014 3:05 am
Contact:

Re: Migration Script not working

Post 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.
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
Post Reply

Return to “Modding help”