Fire on_player_joined_game when loading a singleplayer game

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Post Reply
User avatar
raiguard
Factorio Staff
Factorio Staff
Posts: 452
Joined: Wed Dec 13, 2017 8:29 pm
Contact:

Fire on_player_joined_game when loading a singleplayer game

Post by raiguard »

As per discussion in the #mod-making Discord Channel: when you load a singleplayer game, on_player_joined_game should fire, just like it would when joining a multiplayer game.

Why? I am attempting to make use of the new LuaPlayer.request_translation() capability that was added, so users of my mod can search for items using natural language. Because of the way this feature was implemented, I need to create a "dictionary" of localised strings that match with their prototype names. I do this in on_player_created and on_player_joined_game, in case they change their locale.

The problem is that singleplayer doesn't fire on_player_joined_game when you reload a game. If the player saves, quits, changes their locale, and reloads, there is no good way to update the dictionary with the new locale without some sort of manual action on the player's part.

It sounds pretty easy to fix in theory: just add a command or something the player can do to tell it to update. However, this quickly leads to a problem: every single mod that uses localised dictionaries like this would need to add their own command. It would get pretty annoying if the user had to enter eight different commands to update their locale.

A solution to this would be to make a dictionary lib mod that people could add as a dependency and use. If absolutely everyone used this library, you would only have to enter one command. However, standardized library mods are hugely frowned upon, would not be customizable for specific mods, and would add to the already large library mod bloat.

So, to my suggestion: make it so that on_player_joined_game fires when you load a singleplayer game. This would completely solve the problem and make singleplayer consistent with multiplayer.

Thanks for reading!
Don't forget, you're here forever.

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

Re: Fire on_player_joined_game when loading a singleplayer game

Post by DaveMcW »

Don't you really want on_player_changed_locale()?

User avatar
raiguard
Factorio Staff
Factorio Staff
Posts: 452
Joined: Wed Dec 13, 2017 8:29 pm
Contact:

Re: Fire on_player_joined_game when loading a singleplayer game

Post by raiguard »

No, I'm asking for exactly what I described. There would be many uses for this, beyond what I'm doing.
Don't forget, you're here forever.

Post Reply

Return to “Modding interface requests”