Page 1 of 1

indexing game.x fails in Control.lua

Posted: Fri Jul 15, 2016 10:02 pm
by Glockshna
I'm trying to modify enabled recipes in Control.lua by running the standard

Code: Select all

for i, forces in pairs(game.forces) do
    stuff
end

loop but I'm getting "attempt to index global "game" (a nil value)"

The same loop works fine in migrations. What am I missing?

Re: indexing game.x fails in Control.lua

Posted: Fri Jul 15, 2016 10:28 pm
by DaveMcW
You can only access game through events (and not on_load either).

Re: indexing game.x fails in Control.lua

Posted: Fri Jul 15, 2016 11:00 pm
by Glockshna
DaveMcW wrote:You can only access game through events (and not on_load either).
Alright, maybe you can help me with this then.

I'm trying to make my mod modular such that one can change config options to enable and disable certain parts of the mod. That being said, I don't want to have to put in 700 different researches, I'd like some parts of the mod to share a research. But if a player starts a map with a module disabled and then after researching something that unlocks an item in that module decides to enable the module, I'd like the game to register the research entries and enable the appropriate recipes for the newly enabled module. You can see why a migration file wouldn't work for this. I wanted to just run a check each time the game is loaded to make sure everything is enabled that should be but now I'm stuck as to how I'd accomplish this.

Any insight would be appreciated...

Re: indexing game.x fails in Control.lua

Posted: Fri Jul 15, 2016 11:26 pm
by DaveMcW
I would track modules you have processed in global.modules_processed. Then check every few seconds in on_tick for a new module, and process it.

Re: indexing game.x fails in Control.lua

Posted: Fri Jul 15, 2016 11:59 pm
by Rseding91
Glockshna wrote:
DaveMcW wrote:You can only access game through events (and not on_load either).
Alright, maybe you can help me with this then.

I'm trying to make my mod modular such that one can change config options to enable and disable certain parts of the mod. That being said, I don't want to have to put in 700 different researches, I'd like some parts of the mod to share a research. But if a player starts a map with a module disabled and then after researching something that unlocks an item in that module decides to enable the module, I'd like the game to register the research entries and enable the appropriate recipes for the newly enabled module. You can see why a migration file wouldn't work for this. I wanted to just run a check each time the game is loaded to make sure everything is enabled that should be but now I'm stuck as to how I'd accomplish this.

Any insight would be appreciated...
The game doesn't work in any way that that's supported. Loading a game is never meant to change the game state unless there's some special condition: loading with different mod versions, loading a different map version and so on.

Currently Factorio doesn't support a "config" for mods and as such you're not going to be able to do what you're looking to do.

Re: indexing game.x fails in Control.lua

Posted: Sat Jul 16, 2016 12:22 am
by Glockshna
Rseding91 wrote:
Glockshna wrote:
DaveMcW wrote:You can only access game through events (and not on_load either).
Alright, maybe you can help me with this then.

I'm trying to make my mod modular such that one can change config options to enable and disable certain parts of the mod. That being said, I don't want to have to put in 700 different researches, I'd like some parts of the mod to share a research. But if a player starts a map with a module disabled and then after researching something that unlocks an item in that module decides to enable the module, I'd like the game to register the research entries and enable the appropriate recipes for the newly enabled module. You can see why a migration file wouldn't work for this. I wanted to just run a check each time the game is loaded to make sure everything is enabled that should be but now I'm stuck as to how I'd accomplish this.

Any insight would be appreciated...
The game doesn't work in any way that that's supported. Loading a game is never meant to change the game state unless there's some special condition: loading with different mod versions, loading a different map version and so on.

Currently Factorio doesn't support a "config" for mods and as such you're not going to be able to do what you're looking to do.
Aw, well alright. Should I post a request to make this possible or is it just not going to happen?

I would argue that allowing a config change in a mod to act as a version migration should be possible.

Re: indexing game.x fails in Control.lua

Posted: Sat Jul 16, 2016 12:33 am
by daniel34
Glockshna wrote:Aw, well alright. Should I post a request to make this possible or is it just not going to happen?
Add your request here: viewtopic.php?f=28&t=26166