1. Hello. Im having trouble saving / loading custom player data.
    The end problem is that whenever I saved data, next time I try to load them it fails with a NullReferenceException on the following line :

    Code:
    yds = Interface.Oxide.DataFileSystem?.ReadObject<YattaDatas>("Equity_PlayersDatas");
    Here's the loading code :

    Code:
            void LoadYattaData() {
                Puts("LOADING CUSTOM DATA ...");
                Puts("1a");
                if (Interface.Oxide.DataFileSystem == null) return;
                Puts("1b");
                loadDataTimer.Destroy();
                Puts("1c");
                timer.Repeat(5f, -1, () => { AutoSaveData(); });
                Puts("1d");
                if (yds == null) return;
                Puts("1e");
                yds = Interface.Oxide.DataFileSystem?.ReadObject<YattaDatas>("Equity_PlayersDatas");
                Puts("1e");
                if (yds.data != null) {
                    Puts("No data");
                    playersData = yds.data;
                } else {
                    Puts("Data found");
                    playersData = new Dictionary<ulong, YattaData>();
                }
                Puts("CUSTOM DATA READY");
            }
    
    The error always happens after "1e" if I saved non-empty data on a previous server session. If I save data and there is nothing to actually save, next session will load without an error.

    Here are my classes. Im not sure using a containing class (YattaDatas holding the dictionnary) is necessary, I ended up doing that during various tests to fix the problem.

    Code:
            public class YattaDatas {
                public Dictionary<ulong,YattaData> data;
            }
         
            public class YattaData {
                public bool bearWarned = false;
                public bool wandStop = false;
                public ulong id = 0;
                public string wandMode = "";            public YattaData(BasePlayer bp) {
                    id = bp.userID;
                    wandMode = "none";
                }
            }
    

    Searched the forums for clues but Im running out of ideas to try to fix it. Any help welcome.

    Edit: Tried to switch the whole thing to DynamicConfigFile system, I have the same problem : if the data is empty its ok, if I save something and restart server it fails.
     
    Last edited by a moderator: Jul 4, 2016
  2. Try this:
    Code:
    public class YattaDatas {
                public Dictionary<ulong,YattaData> data = new Dictionary<ulong, YattaData>();
            }
    YattaDatas yds; // If you have it then forget about this line.
    
     
  3. Didnt change the result :(

    I tried going from scratch, no problem with loading / saving a string, so I guess it has something to do with the type of data / structure im trying to save. Still investigating.

    EDIT: FINALLY FIXED (i think) !
    Im not sure how, tough. I just cleaned lots of stuff and it fell in place somehow. Sorry I cant be of anymore help if someone comes into a similar issue :(
     
    Last edited by a moderator: Jul 4, 2016