:: StoryTitle Player Statistics in Snowman :: UserScript[script] $(function() { // Create a global setup object window.setup = window.setup || {}; // Create a global propety on the setup object window.setup.stats = {}; // Create (and overwrite) the use of 's' var s = window.setup.stats; s.empathy = 10; s.intelligence = 10; s.totalPoints = 5; $("#empathyIncrease").click(function(){ if(s.totalPoints > 0) { setup.stats.empathy++; s.totalPoints--; $("#empathyStat").text(s.empathy); $("#pointsStat").text(s.totalPoints); } }); $("#empathyDecrease").click(function(){ if(s.empathy > 0) { s.empathy--; s.totalPoints++; $("#empathyStat").text(s.empathy); $("#pointsStat").text(s.totalPoints); } }); $("#intelligenceIncrease").click(function(){ if(s.totalPoints > 0) { s.intelligence++; s.totalPoints--; $("#intelligenceStat").text(s.intelligence); $("#pointsStat").text(s.totalPoints); } }); $("#intelligenceDecrease").click(function(){ if(s.intelligence > 0) { s.intelligence--; s.totalPoints++; $("#intelligenceStat").text(s.intelligence); $("#pointsStat").text(s.totalPoints); } }); $("#pointsReset").click(function(){ s.empathy = 10; s.intelligence = 10; s.totalPoints = 5; $("#empathyStat").text(s.empathy); $("#intelligenceStat").text(s.intelligence); $("#pointsStat").text(s.totalPoints); }); // Add a randomInt function to the Math global Math.randomInt = function(min, max) { min = Math.ceil(min); max = Math.floor(max); return Math.floor(Math.random() * (max - min)) + min; }; $("#testIntelligence").click(function() { var result = s.intelligence + Math.randomInt(1,6); if(result >= 15) { $("#intelligenceResult").text("Success! (" + result + " >= 15)"); } else { $("#intelligenceResult").text("Failure! (" + result + " < 15)"); } console.log("Test!"); }); $("#testEmpathy").click(function() { var result = s.empathy + Math.randomInt(1,6); if(result >= 15) { $("#empathyResult").text("Success! (" + result + " >= 15)"); } else { $("#empathyResult").text("Failure! (" + result + " < 15)"); } }); }); :: Start Empathy: Intelligence: Empathy: 10 Intelligence: 10 Remaining Points: 5