我的代码: (有1200行代码,我需要的只是变量),我需要帮助填写save();和load();因此它使用localStorage加载并保存所有变量(因此您可以在同一台PC上随时访问它)。谢谢你的帮助。
var xp = 0;
var xpN = 10;
var level = 1;
var population = 4;
var populationLimit = 5;
var populationProd = 0;
var questpoints = 0.5;
var questpointsboost = 1;
var autoquest = "false";
//Resources
var gold = 11;
var food = 25;
var wood = 0;
var stone = 0;
var iron = 0;
var goldmax = 15;
var foodmax = 5;
var woodmax = 5;
var stonemax = 5;
var ironmax = 5;
var prize = 0;
var trade1 = 0;
var trade2 = 0;
var item1 = 0;
var item2 = 0;
var userAns = "";
// workers
var soldier = 12;
var randomnumber = 0;
var farmer = 0.1;
var lumberjack = 0;
var stoneminer = 0;
var ironminer = 0;
var farmercount = 0;
var maxfarmer = 4;
var lumberjackcount = 0;
var lumberjackmax = 0;
var stoneminercount = 0;
var stoneminermax = 0;
var ironminercount = 0;
var ironminermax = 0;
function save(){
}
function load(){
}
答案 0 :(得分:1)
您可以保存这样的值
>localStorage.getItem('variable_name')
然后你可以得到那个值
var playerName = 'player';
localStorage.setItem(playerName, 'John Doe');
您可以将密钥存储在变量中,然后根据该密钥从localStorage获取该值
var player = localStorage.getItem(playerName);
下次你可以获得该值
transform