Equivalent event to on_player.joined_game in single player?

Place to get help with not working mods / modding interface.
User avatar
_Attila_
Long Handed Inserter
Long Handed Inserter
Posts: 75
Joined: Sun Jan 06, 2019 2:46 pm
Contact:

Equivalent event to on_player.joined_game in single player?

Post by _Attila_ »

I want to detect when a player starts a new playing session, so that session specific variables can be set.
on_player_joined_game seems to do the job for multi-player, but there is no event when a single player save is loaded.

As an illustrative example: How would I be able to print "Welcome back" when a save is loaded?
Attila's QuickBar Mod - Auto-links hand crafted item to first free quickbar slot if not already linked.
Attila's Signals Mod - Alternate signals to use in same circuit as standard signals.
Attila's Zoom Mod - Modifies zoom functionality.
Bilka
Factorio Staff
Factorio Staff
Posts: 3310
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Equivalent event to on_player.joined_game in single player?

Post by Bilka »

How would I be able to print "Welcome back" when a save is loaded?
There is no event that allows this.

In general, "I want to detect when a player starts a new playing session, so that session specific variables can be set." is not possible because it would not be save-load stable, but save-load stability is required for multiplayer, so we do not allow Lua to break it.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
User avatar
_Attila_
Long Handed Inserter
Long Handed Inserter
Posts: 75
Joined: Sun Jan 06, 2019 2:46 pm
Contact:

Re: Equivalent event to on_player.joined_game in single player?

Post by _Attila_ »

Well, this obviously makes sense to you, but I don't get it. :oops:

A player can generate an event by clicking something. On this event I can print "Welcome back", but I can't do this in an event handler automatically when a save is loaded in single player mode?

Why not just send the player_joined_game event when a new session is started by a player - single or mp? The event would be handled the same way in both cases.
Attila's QuickBar Mod - Auto-links hand crafted item to first free quickbar slot if not already linked.
Attila's Signals Mod - Alternate signals to use in same circuit as standard signals.
Attila's Zoom Mod - Modifies zoom functionality.
quyxkh
Smart Inserter
Smart Inserter
Posts: 1031
Joined: Sun May 08, 2016 9:01 am
Contact:

Re: Equivalent event to on_player.joined_game in single player?

Post by quyxkh »

I maintain a global.is_multiplayer. You can check that in on_load, if it's off I set a self-cancelling on_tick, otherwise on_player_joined_game, either way I update global.is_multiplayer from game.is_multiplayer() when the selected event fires. So if a saved singleplayer map's being reloaded multiplayer for the first time, the server will do a one-off on_tick when there's no players yet, no desync there, and all players joining will see the updated value and do opjg correctly; if a saved multiplayer map's being loaded singleplayer I don't see how to do the right thing cleanly. You show up as a saved player, the only way I can figure to do it would be to check global.is_multiplayer against game.is_multiplayer() pretty much everywhere and fire the sp-join code on a mismatch. I guess a permanent 5-second nth_tick would be negligible enough overhead.
User avatar
_Attila_
Long Handed Inserter
Long Handed Inserter
Posts: 75
Joined: Sun Jan 06, 2019 2:46 pm
Contact:

Re: Equivalent event to on_player.joined_game in single player?

Post by _Attila_ »

Thanks for the info, I will try this.
Attila's QuickBar Mod - Auto-links hand crafted item to first free quickbar slot if not already linked.
Attila's Signals Mod - Alternate signals to use in same circuit as standard signals.
Attila's Zoom Mod - Modifies zoom functionality.
Post Reply

Return to “Modding help”