So I'm making my incremental game, Periodic Alchemy, and I'm trying to make something that ensures that a save keeps all the new variables in another version. In order to save, I take a variable, "player", which includes all my variables inside it, and make it into a Base64 string that you can copy.
In almost every new version, however, I add new variables. If a player uses their old save on a new version with new variables, then those new variables are lost and the new functions break. So when you load the game, the game checks to see if that old save_data contains certain variables, and if a variable is not included, the game adds that variable to the save data. I don't know, however, how to do that. Here is my "player" code:
var player = {
upQuarkClicks: 0,
electronClicks: 0,
downQuarkClicks: 0,
auto_up_quark_clicks: 0,
auto_electron_clicks: 0,
auto_down_quark_clicks: 0,
auto_proton_clicks: 0,
auto_neutron_clicks: 0,
up_quark_click_cost: 15,
electron_click_cost: 15,
down_quark_click_cost: 15,
proton_click_cost: 15,
neutron_click_cost: 15,
upgrade_up_quark_1_cost: 50,
upgrade_electron_1_cost: 50,
upgrade_down_quark_1_cost: 50,
auto_up_quark_clicks_amount: 1,
auto_electron_clicks_amount: 1,
auto_down_quark_clicks_amount: 1,
auto_proton_clicks_amount: 1,
auto_neutron_clicks_amount: 1,
upgrade_up_quark_click_1_bought: "False",
upgrade_electron_click_1_bought: "False",
upgrade_down_quark_click_1_bought: "False",
proton_up_quark_cost: 2,
proton_down_quark_cost: 1,
neutron_up_quark_cost: 1,
neutron_down_quark_cost: 2,
protonClicks: 0,
neutronClicks: 0,
hydrogen2DeuteriumClicks: 0,
hydrogen1ProtiumClicks: 0,
hydrogen3TritiumClicks: 0,
helium3Clicks: 0,
helium4Clicks: 0,
lithium6Clicks: 0,
lithium7Clicks: 0
};
So, let's say I added a new variable: lithium_7_bought: "false". This new variable is not in the old save data, and so is erased by the load. How do I add it in if it is not found?