So I recently was messing around with the Basecreature and did some serialization. The Script Works completely fine but serialization wanted to delete like serial 0x000001 and so on, Does this mean I messed up on the serialization at all or is this a normal thing and I just have to reload the account information/backups. Cause Regardless whenever I mess around with any serialization this tends to always do this. I was just wonderings if I messed it up myself or is this a common thing that always happens? Also, I tend to just delete the save as it's just a test server and restart the server as a new compile and it doesn't have issues afterwards.
 
It means you did not serialize correctly. This may or may not have long term problems with the Server. If you are able to delete and start over, then it saves and loads fine after that, it means the serialization was fine on it's own and simply did not create proper backward compatibility. This is fine if you are OK with it, but is not optimal in most situations. If it compiles and loads with a new Server, but then fails to save or reload after save, then you have a real problem.

Serialization 101:

When you save, it should place all stored variables in a particular order such that you are able to read them back during load in the same order. If you add something to the save routine, normally you increment a version number so that the load processor can tell that the version has changed and will use the correct case statement accordingly.

Example:

Pre-change script:

C#:
        public override void Serialize(GenericWriter writer)
        {
            base.Serialize(writer);

            writer.WriteInt(0); // version

            writer.Write(variable_zero);
        }

        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize(reader);

            int version = reader.ReadInt();
            
            switch(version)
            {
                case 0:
                {
                    variable_zero = reader.ReadInt();
                    break;
                }
            }

        }

Post-change script:

C#:
        public override void Serialize(GenericWriter writer)
        {
            base.Serialize(writer);

            writer.WriteInt(1); // version

            writer.Write(variable_one); // This is added first
            writer.Write(variable_zero);
        }

        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize(reader);

            int version = reader.ReadInt();
            
            switch(version)
            {
                case 1: // the first time the server loads it will ignore this code because version used to be 0
                {
                    variable_one = reader.ReadInt();
                    goto case 0;
                }
                case 0:
                {
                    variable_zero = reader.ReadInt();
                    break;
                }
            }

        }
 
Thank you Lokai, Appreciate the help. so whenever I have to do serialization I have to increase the version number with it and add a case matching the new version, that's where I went wrong with it the first time, I forgot to increase the version # and the case, I just simply wrote the code down under the last line of the serialization, and comment the version number above it but not actually changing it within the script.
 
Back