writer.Write (2); // This is the version number. Perhaps we just changed this from 1 to 2. You will see why shortly
// Let's say these varialbes were added later.
writer.Write( someVariableThree ); // pretend variable three is a bool
writer.Write( someVariableFour ); // pretend variable four is a double
// Let's also say these were the first variables we created when the script was first written
writer.Write( someVariableOne ); // variable one is an int
writer.Write( someVariableTwo ); // and variable two is another bool
int version = reader.ReadInt(); // we wrote an int to memory first, so we have to read one first. In this case, the version number
switch( version )
{
case 2: // This is the case that will run when the server loads after saving the (2) from above
{
someVariableThree = reader.ReadBool(); // the compiler is expecting a bool, so we give it the same one we saved first before
someVariableFour = reader.ReadDouble(); // you see the pattern here?
goto case 1;
}
// If there is a previous version of the server saved where a (1) was written, it would not contain the variables three
// and four so it would start here. In this case it would only read these.
case 1:
{
someVariableOne = reader.ReadInt();
someVariableTwo = reader.ReadBool();
break;
}
case 0: // This may have been the first iteration of the server, a long time ago
{
break;
}
}
We use essential cookies to make this site work, and optional cookies to enhance your experience.