Page 1 of 1

onload with multiplayer

Posted: Sun Feb 01, 2015 9:26 pm
by FreeER
so I updated the Time Display mod for multiplayer (with some help from FishSandwich) and as briefly mentioned in an edit on the third page I encountered an issue with game.onload not having a list of players, I kind of assume this is actually to be expected to some extent though I also assume this will break how several mods were working in singleplayer.

Does anyone have a recommended way to deal with this kind of situation or is it just a matter of doing extra checks in ontick now?

edit: hm, perhaps this is better as a bug report since my guess is that during the game (autosaves) onload should still have the list of players, maybe?

Re: onload with multiplayer

Posted: Sun Feb 01, 2015 10:55 pm
by Choumiko
FreeER wrote:so I updated the Time Display mod for multiplayer (with some help from FishSandwich) and as briefly mentioned in an edit on the third page I encountered an issue with game.onload not having a list of players, I kind of assume this is actually to be expected to some extent though I also assume this will break how several mods were working in singleplayer.

Does anyone have a recommended way to deal with this kind of situation or is it just a matter of doing extra checks in ontick now?

edit: hm, perhaps this is better as a bug report since my guess is that during the game (autosaves) onload should still have the list of players, maybe?
I think i remember facing a similar problem a while ago. I added the code in onplayercreated too (and in a bunch of other places.. throw code everywhere until it works :D ) and the problem disappeared. Perhaps onplayercreated is called whenever a player joins a mp game? Never bothered testing, not that helpfull of a reply i guess :?
Not sure how onload exactly works, but in a mp game it can't possibly have a list of players as anyone could join or only join the game once and never return?

events like onplayerjoined/onplayerleft etc would be helpfull i guess

Re: onload with multiplayer

Posted: Mon Feb 02, 2015 12:52 am
by L0771
if you use player.name, i think you need to know if player.name was set

Code: Select all

if player.name ~= "" then
	...
end
I think you don't need restart gui every load

Code: Select all

game.onload(function()
  -- restore gui state on load or right after save
  for playerindex, player in ipairs(game.players) do
    set_defaults(playerindex)
	if not player.gui[glob[player.name].location][FRAME_NAME] then
		init_gui(playerindex)
	end
    do_update(playerindex)
  end
end)
The list of players, config, gui and others stuff are deleted with game.removeofflineplayers

I haven't problem in MP, i don't know why but in a new game with your code 2/10 games i had ctd

Re: onload with multiplayer

Posted: Mon Feb 02, 2015 1:23 am
by FreeER
L0771 wrote:if you use player.name, i think you need to know if player.name was set
hm... I'm going to go out on a limb and assume that people playing in multiplayer will set a name...I didn't want to use the playerindex because I assume those could change as players leave (after game.removeofflineplayers is called) which would end up making the code treat the 'same' players as different players. I'm not certain but maybe it could be indexed based on the actual player object? However, that would likely create new, distinct, player objects after game.removeofflineplayers is called and they join again, which would lead to lost settings that the nickname index wouldn't have a problem with. Not a huge issue admittedly, but something to take note of.
L0771 wrote:I think you don't need restart gui every load
Originally it was set to remove the gui onsave (so it didn't leave orphaned guis when the mod was removed), as such onload the gui needed to be restored with init_gui. That worked fine in SP, not so well in MP it turns out.
L0771 wrote:i don't know why but in a new game with your code 2/10 games i had ctd
Interesting, I didn't experience any ctds in the limited testing I did, neither did FishSandwich as far as I could tell. So no idea what's causing that.

P.S.
apparently FishSandwich had to comment out both onsave AND onload to get it to work (mostly) as intended, I, however, have no idea why/how onload could make the gui disappear (it's very much intended to do the opposite).
Choumiko wrote:Perhaps onplayercreated is called whenever a player joins a mp game?
From my understanding it's called when a player first joins the game (or after they've left, game.removeofflineplayers is called, and they join again).
Choumiko wrote:Not sure how onload exactly works, but in a mp game it can't possibly have a list of players as anyone could join or only join the game once and never return?
Well... it's a bit complicated to think about. I can understand it not having a list of all players since there are only two forces and it just needs to keep track of which force entities belong to (and what has been researched, etc. for those forces), not sure how that'll be handled in 12.x with separate forces, except I'm assuming that when you reload a save and players rejoin it that they start where they were when the game was saved so it has to be able to reconnect the joining players to the players/characters who were there previously and thus would need a list... note: I haven't played MP so... I'm really doing a lot of this 'blind', I could be entirely wrong on some of my assumptions. Also, when the game is first started from a save, I'd kind of expect it to have game.players[1] (or whatever the proper index would be for the player that opened the save, not sure how that's handled if they had a different index during the game then saved it and loaded it later theirselves).
However in the simpler case and the one causing the most issue really, autosaves, it _could_ have a list of all current players, at least I would think so, because, well they're still connected...