When to edit 'game' on load?

Place to get help with not working mods / modding interface.
Post Reply
Honktown
Filter Inserter
Filter Inserter
Posts: 309
Joined: Thu Oct 03, 2019 7:10 am
Contact:

When to edit 'game' on load?

Post by Honktown » Tue Dec 03, 2019 10:12 pm

I'm using a mod that has saved data, but doesn't load it properly. It needs things like shooting speed upgrades, mining productivity, etc which are stored in the 'game' table.

on_init only seems to run on world initialization/creation.

on_load doesn't have the 'game' table loaded.

on_configuration_changed only applies when the configuration is changed (unsurprisingly).

Event on_player_joined_game and on_player_created don't trigger for me in single-player (I'm printing a message to log in a function that's used for both and there's nothing).

Is there a lib function or event I can use when a save is loaded in single-player AND has the game table loaded, or if the technology bonuses are loaded in global somewhere else?

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

Re: When to edit 'game' on load?

Post by DaveMcW » Tue Dec 03, 2019 10:32 pm

Use both on_init and on_player_created. This will catch every player.

Honktown
Filter Inserter
Filter Inserter
Posts: 309
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: When to edit 'game' on load?

Post by Honktown » Tue Dec 03, 2019 10:41 pm

DaveMcW wrote:
Tue Dec 03, 2019 10:32 pm
Use both on_init and on_player_created. This will catch every player.
And like I said, they do not run in single player when you load a save. I added both a game.print and log() message to both, besides the functions that SHOULD be running. Not a damn thing.

edit:

viewtopic.php?t=38207

I found an old discussion, if it's accurate. on_init is only ran on world creation, and on_player_created is only ran when a player first joins (and wouldn't apply to a character in a running game).

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

Re: When to edit 'game' on load?

Post by DaveMcW » Tue Dec 03, 2019 11:18 pm

Honktown wrote:
Tue Dec 03, 2019 10:41 pm
They do not run in single player when you load a save.
So you add the mod, then save/load the game, then want another event? It sounds like you are doing it wrong. You should design your mod to not care about save/load.

Honktown
Filter Inserter
Filter Inserter
Posts: 309
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: When to edit 'game' on load?

Post by Honktown » Tue Dec 03, 2019 11:40 pm

DaveMcW wrote:
Tue Dec 03, 2019 11:18 pm
Honktown wrote:
Tue Dec 03, 2019 10:41 pm
They do not run in single player when you load a save.
So you add the mod, then save/load the game, then want another event? It sounds like you are doing it wrong. You should design your mod to not care about save/load.
It's not my mod. The mod adds bonuses to stuff like shooting speed, etc as the game goes. For whatever reason the effects aren't persistent on loading a save.

As an example I have 10% shooting speed bonus from normal research, and 50% from the mod. On load, I only get 10%.

Usually the effects don't seem to be consistently loaded, or I'm just missing the pattern. Something like damage sometimes gets boosted on load, but other times doesn't.

Additionally, the author messed up one bonus, and it only adds additional effects after being fixed (+10%), and not the effect of all the preceding bonuses (the bonuses are from levels). It seems really, really dumb there's not an obvious point in the load cycle which is after the world loads and game is present (a run-once per load)

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

Re: When to edit 'game' on load?

Post by DaveMcW » Wed Dec 04, 2019 12:14 am

Then the mod author is doing it wrong and the mod is broken.

Honktown
Filter Inserter
Filter Inserter
Posts: 309
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: When to edit 'game' on load?

Post by Honktown » Wed Dec 04, 2019 12:27 am

Working on it. I think I introduced an extra end and it was screwing up some scopes. Of course Lua wouldn't report anything. As expected, none of the events trigger because there's just no damn place to run something after the game is loaded.

I don't think there's a value of "base" bonus from vanilla researches. Correct me if I'm wrong. I have to run on an assumption that a "bad" bonus will be less than the expected amount, but that assumption would fail if the base bonus is equal to or greater than the mods bonus. Only way I can get around it is to index all the researches which apply a bonus to a attribute and re-calculate based on which have been completed. Phrasing it that way doesn't seem that bad, now that I'm thinking about it. If I hard-coded vanilla research it would under-calculate if a different mod added bonuses to attributes.

PyroFire
Fast Inserter
Fast Inserter
Posts: 234
Joined: Tue Mar 08, 2016 8:18 am
Contact:

Re: When to edit 'game' on load?

Post by PyroFire » Wed Dec 04, 2019 2:26 am

"Game" is available during on_init and on_configuration_changed, as well as when running migrations.

If you need to access game earlier (or during on_load), you're doing something horribly wrong.

Honktown
Filter Inserter
Filter Inserter
Posts: 309
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: When to edit 'game' on load?

Post by Honktown » Wed Dec 04, 2019 7:14 am

I got it. I was able to make a function/command and call it, which works for me because I only needed to recalculate things once.

I could use advice if someone sees this: where is research completed stored? I tried dumping some things like game.forces["player"].technologies but I think that's actually a function (I didn't try calling it - it may return the table for which I'm looking)

Post Reply

Return to “Modding help”

Who is online

Users browsing this forum: No registered users