When you save, save the instance ID alongside each instance you save, and write variables containing instances IDs as-is. As an example, this is what your save data may look like in JSON form:
Code:
{
"instances": [
{
"id": 100aaa,
...
},
{
"id": 100bbb,
...
},
...
],
"current_bat": 100aaa,
...
}
As you load and re-create the instances, create a map pairing the old instance ID (i.e. the one read from the saved data) and the re-created new instance ID (i.e. the corresponding one returned by
instance_create_*()). Here's what the pairing map may look like in JSON form:
Code:
{
"100aaa": 100xxx,
"100bbb": 100yyy,
...
}
To finish, simply use the pairing map to translate the loaded instance ID into a re-created instance ID.
Code:
global.current_bat = pairing_map[? string(loaded_data[? "current_bat"])];
If you're going to be using maps and lists to store your data, I strongly recommend that you familiarize yourself with
data modeling in MongoDB. Most of the principles work the exact same way with plain JSON, and it really isn't all that hard.