Using onload
Posted: Sun Jun 15, 2014 6:17 pm
I'm writing a mod that, among other things, modifies some existing technologies and recipes, and adds a new item (unlocked by one of the existing technologies).
If I enable the mod and load a saved game created without the mod, the technologies and recipes remain with the original prototype, and the recipe for the new item is disabled despite the unlocking technology having been researched already.
If I write the following commands in the in-game console, everything is fine:
However, I want it to work without having to type commands in-game. So I added to the mod a file control.lua with the following:
I figured onload would be triggered when I load the saved game and the commands will be executed. However, this does not happen. Instead, the commands are only run a minute or so after the game was loaded. After that everything works, however, I also get the message "Can't save map, entity list of entities staged for update of links is not empty."
So, why is this not working? Is this a correct usage of "onload"? Is there a better way to achieve the same effect? And what is the meaning of this cryptic message?
If I enable the mod and load a saved game created without the mod, the technologies and recipes remain with the original prototype, and the recipe for the new item is disabled despite the unlocking technology having been researched already.
If I write the following commands in the in-game console, everything is fine:
Code: Select all
game.player.force.resettechnologies()
game.player.force.resetrecipes()
if game.player.force.technologies["robotics"].researched then
game.player.force.recipes["hyper-inserter"].enabled=true
end
Code: Select all
game.onload(function()
game.player.force.resettechnologies()
game.player.force.resetrecipes()
if game.player.force.technologies["robotics"].researched then
game.player.force.recipes["hyper-inserter"].enabled=true
end
end
)
So, why is this not working? Is this a correct usage of "onload"? Is there a better way to achieve the same effect? And what is the meaning of this cryptic message?