indexing game.x fails in Control.lua

Place to get help with not working mods / modding interface.
Post Reply
Glockshna
Long Handed Inserter
Long Handed Inserter
Posts: 50
Joined: Tue Jan 21, 2014 7:57 am
Contact:

indexing game.x fails in Control.lua

Post 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?

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3700
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: indexing game.x fails in Control.lua

Post by DaveMcW »

You can only access game through events (and not on_load either).

Glockshna
Long Handed Inserter
Long Handed Inserter
Posts: 50
Joined: Tue Jan 21, 2014 7:57 am
Contact:

Re: indexing game.x fails in Control.lua

Post 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...

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3700
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: indexing game.x fails in Control.lua

Post 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.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13219
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: indexing game.x fails in Control.lua

Post 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.
If you want to get ahold of me I'm almost always on Discord.

Glockshna
Long Handed Inserter
Long Handed Inserter
Posts: 50
Joined: Tue Jan 21, 2014 7:57 am
Contact:

Re: indexing game.x fails in Control.lua

Post 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.

daniel34
Global Moderator
Global Moderator
Posts: 2761
Joined: Thu Dec 25, 2014 7:30 am
Contact:

Re: indexing game.x fails in Control.lua

Post 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
quick links: log file | graphical issues | wiki

Post Reply

Return to “Modding help”