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
1
100%
No, I would not like this feature
0
No votes
 
Total votes: 1

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

Attributes to handle changes in variable names

Post by Joel »

Status

Requested

Complexity

3/10

Description

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:
[ES3FieldName("myVariable")]
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:
[ES3FieldName("myVariable")]
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);
	break;
For more information on creating ES3Types, see Creating an ES3Type.
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Post Reply