Attributes to handle changes in variable names

Vote for new features, or make your own requests here.
Post Reply

Attributes to handle changes in variable names

Yes, I would like this feature
No, I would not like this feature
No votes
Total votes: 1

User avatar
Moodkie Staff
Posts: 4485
Joined: Wed Nov 07, 2012 10:32 pm

Attributes to handle changes in variable names

Post by Joel »






When the name of a variable in a script changes, this invalidates the save data for it. We could account for changes by adding an attribute which specifies a persistent field name:
public int myVariable;
If the name of the variable were to change, the value could still be retrievable, as the attribute value would be the same:
public int myNewVariable;
There would be a performance impact to performing this check for each field, so this will need to be weighed up against the benefits. This would also not be possible for classes for which an explicit ES3Type exists.

Currently this can be achieved (albeit with more effort) by creating an ES3Type for the class containing the variable, and manually modifying the Read and Write of that variable to use the original variable name. I.e.
// Inside WriteComponent(obj,writer)
writer.WriteProperty("oldVariableName", instance.newVariableName, ES3Type_int.Instance);

// Inside ReadComponent<T>(reader, obj)
case "oldVariableName":
	instance.newVariableName = reader.Read<System.Single>(ES3Type_float.Instance);
For more information on creating ES3Types, see Creating an ES3Type.
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started

Post Reply