Since I haven't found it explained thoroughly in here and it might be really useful for new scripters...
If you just add some variables in the serialize and deserialize methods, the server still might not see the variables' values on existing mobiles / items / whatever and might want to delete them.
There's a simple solution to that.
If you have added new variables in the Serialize and Deserialize methods
eg.
Code:
(...)
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt();
switch ( version )
{
#region MyRegion
case 26:
{
var1 = reader.ReadLong();
var2 = reader.ReadInt();
var3 = reader.ReadString();
gotocase 25;
}
#endregion
(...)
public override void Serialize( GenericWriter writer )
{
(...)
writer.Write( (int) 26 ); // VERSION!
#region MyRegion
writer.Write( (long)var1 );
writer.Write( (int)var2 );
writer.Write( (string)var3 );
#endregion
(...)
You should make sure the script doesn't lead to an error when an object without those properties (old object) is loaded.
An easy way to do that supposing you increased the version number when adding the new properties would be to those lines:
Code:
#region MyRegion
if (version < 26)
{
var1 = [value 1];
var2 = [value 2];
var3 = "[value3]";
}
#endregion
in the Deserialize method right after the end of the switch function:
Code:
case 0:
{
break;
}
}
That should prevent the server from throwing any errors and deleting existing objects.