Mod state in loaded and reconnected games

Discussion in 'Mod Support' started by wondible, May 6, 2015.

  1. wondible

    wondible Post Master General

    Messages:
    3,279
    Likes Received:
    2,078
    We've been able to sort of manage reconnecting to online games via lobbyid. Someone recently told me that a mod doesn't remember anything over save/load. Is there any way to identify when we are in the "same" game, either due to save/load or disconnect?
  2. exterminans

    exterminans Post Master General

    Messages:
    1,890
    Likes Received:
    1,014
    Well, you do have access to the local storage API, at least I think that one is active in Coherent by default.

    Code:
    localStorage.setItem("key","value");
    localStorage.getItem("key");
    Just make sure you are reusing keys, don't pollute the storage! There is no garbage collection, so everything you store in Coherent should actually be persistent.
  3. cola_colin

    cola_colin Moderator Alumni

    Messages:
    12,125
    Likes Received:
    16,255
    PA even uses the local storage for all settings, just like practically all mods do ;)
    The issue wondible is talking about is: How do we detect that the player is in "that" game again?
  4. exterminans

    exterminans Post Master General

    Messages:
    1,890
    Likes Received:
    1,014
    You mean like:
    Code:
    var lobby = ko.observable().extend({ session: 'lobbyId' });
    var key = "lastLobbyId";
    if(localStorage.getItem(key) === lobby()) {
        // Do your stuff
    } else if(lobby()) {
        localStorage.setItem(key,lobby());
    }
    
    EDIT: Scratch that. @cola_colin, you confused me. He wants a way to identify savegames, not lobbies.

    That's slightly more ugly.

    There is no strong, unique identifier whatsoever stored in saved games. None.

    Only the originally recorded start time and the original system name. And I don't know whether either of these is even being restored when loading the save game. Possibly only the owner of the lobby can see at load time, from which save game file name the lobby is being restored.
    Last edited: May 24, 2015

Share This Page