Basic localStorage usage

From SmartBots Developers Docs
Jump to: navigation, search


This script displays the basic usage of Bot_Playground/Built-in_Functions/localStorage.set localStorage.set() and Bot_Playground/Built-in_Functions/localStorage.get localStorage.get() functions.

var CONFIG = {};

restoreConfig();

CONFIG.runs++;
console.log("This script is starting for " + CONFIG.runs + " time");

saveConfig();


function restoreConfig() {
	var cnf = localStorage.get("my_config");
	CONFIG = { runs: 0 };
	
	if(typeof(cnf) != "undefined" && cnf != "") {
		CONFIG = JSON.parse(cnf);
	}
}

function saveConfig() {
	localStorage.set("my_config", JSON.stringify(CONFIG));
}