User prompt
Persist Times Rolled counter through resets.
User prompt
Please fix the bug: 'Uncaught TypeError: setInterval is not a function' in or related to this line: 'timeSinceLastResetInterval = setInterval(function () {' Line Number: 380
User prompt
make time since last reset count up until reset button is pressed.
User prompt
Increase time since last reset after every reset.
User prompt
Change 'Hat = 60' text to Hat = 60: 0. Add 1 to Hat = 60: 0 every time dice side is 6. Increase this counter separately of other prize counters.
User prompt
Change 'Claw = 50' text to Claw = 50: 0. Add 1 to Claw = 50: 0 every time dice side is 5. Increase this counter separately of other prize counters.
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'getItem')' in or related to this line: 'timesRolled = parseInt(localStorage.getItem('timesRolled')) || 0;' Line Number: 265
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'getItem')' in or related to this line: 'timesRolled = parseInt(localStorage.getItem('timesRolled')) || 0;' Line Number: 253
User prompt
Change 'Snake = 40' text to Snake = 40: 0. Add 1 to Snake = 40: 0 every time dice side is 4. Increase this counter separately of other prize counters.
User prompt
Increase prize counters separately
User prompt
Change 'Choc = 30' text to Choc = 30: 0. Add 1 to Choc = 30: 0 every time dice side is 3
User prompt
Make Prizes Won table text permanently displayed
User prompt
Change 'Rose = 20' text to Rose = 20: 2. Add 1 to Rose = 20: 0 every time dice side is 2
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'split')' in or related to this line: 'var bearPrizeText = prizesWonTxt.text.split('\n');' Line Number: 199
User prompt
Add 1 to Bear = 10: 0 every time dice side is 1
User prompt
Add 1 to Bear = 10 every time dice side is 1
User prompt
Change 'Bear = 10' text to Bear = 10: 0
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'getItem')' in or related to this line: 'timesRolled = parseInt(localStorage.getItem('timesRolled')) || 0;' Line Number: 219
User prompt
Delete bear won text pop-up
User prompt
Change Prizes won text to Red
User prompt
List prizes won text vertically
User prompt
Decrease size of prizes won text and make it fit the screen
User prompt
Add Prizes Won: Bear = 10, Rose = 20, Choc = 30, Snake = 40, Claw = 50, Hat = 60' text underneath time since last reset.
User prompt
Make 'Bear Won' text disappear after 2 seconds.
/**** * Classes ****/ //<Assets used in the game will automatically appear here> // Dice class to represent a dice var Dice = Container.expand(function () { var self = Container.call(this); // Create and attach dice asset var diceGraphics = self.attachAsset('dice', { anchorX: 0.5, anchorY: 0.5 }); // Set initial value and texture self.value = 1; diceGraphics.texture = LK.getAsset('dice1', {}).texture; // Method to roll the dice self.roll = function () { self.value = Math.floor(Math.random() * 6) + 1; diceGraphics.texture = LK.getAsset('dice' + self.value, {}).texture; totalCashTxt.setText('Total Cash: ' + totalCashWon); timesResetTxt.setText('Times Reset: ' + timesReset); }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Global variables to keep track of individual prizes won var bearPrizesWon = 0; var rosePrizesWon = 0; var chocPrizesWon = 0; var snakePrizesWon = 0; var clawPrizesWon = 0; var hatPrizesWon = 0; // Global variable to keep track of current cash // Create score text var scoreTxt = new Text2('Dice Side: 1', { size: 100, fill: "#ffffff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Create cash won text var cashTxt = new Text2('Cash Won: 10', { size: 75, fill: "#ffffff" }); cashTxt.anchor.set(0.5, 0); cashTxt.y = scoreTxt.height + 20; // Position cash text below score text LK.gui.top.addChild(cashTxt); // Create current cash text var currentCashTxt = new Text2('Current Cash: 0', { size: 75, fill: "#ffffff" }); currentCashTxt.anchor.set(0.5, 0); currentCashTxt.y = cashTxt.y + cashTxt.height + 20; // Position current cash text below cash won text LK.gui.top.addChild(currentCashTxt); // Create total cash text var totalCashTxt = new Text2('Total Cash: 0', { size: 75, fill: "#ffffff" }); totalCashTxt.anchor.set(0.5, 0); totalCashTxt.y = currentCashTxt.y + currentCashTxt.height + 20; // Position total cash text below current cash text LK.gui.top.addChild(totalCashTxt); // Create total time text var totalTimeTxt = new Text2('Total Time: 0s', { size: 75, fill: "#ffffff" }); totalTimeTxt.anchor.set(0.5, 0); totalTimeTxt.y = totalCashTxt.y + totalCashTxt.height + 20; // Position total time text below total cash text LK.gui.top.addChild(totalTimeTxt); // Create current time text var currentTimeTxt = new Text2('Current Time: 0s', { size: 75, fill: "#ffffff" }); currentTimeTxt.anchor.set(0.5, 0); currentTimeTxt.y = totalTimeTxt.y + totalTimeTxt.height + 20; // Position current time text below total time text LK.gui.top.addChild(currentTimeTxt); // Create times rolled text var timesRolledTxt = new Text2('Times Rolled: 0', { size: 75, fill: "#ffffff" }); timesRolledTxt.anchor.set(0.5, 0); timesRolledTxt.y = currentTimeTxt.y + currentTimeTxt.height + 20; // Position times rolled text below current time text LK.gui.top.addChild(timesRolledTxt); // Create times reset text var timesResetTxt = new Text2('Times Reset: 0', { size: 75, fill: "#ffffff" }); timesResetTxt.anchor.set(0.5, 0); timesResetTxt.y = timesRolledTxt.y + timesRolledTxt.height + 20; // Position times reset text below times rolled text LK.gui.top.addChild(timesResetTxt); // Create time since last roll text var timeSinceLastRollTxt = new Text2('Time Since Last Roll: 0s', { size: 75, fill: "#ffffff" }); timeSinceLastRollTxt.anchor.set(0.5, 0); timeSinceLastRollTxt.y = timesResetTxt.y + timesResetTxt.height + 20; // Position time since last roll text below times reset text LK.gui.top.addChild(timeSinceLastRollTxt); // Create time since last reset text var timeSinceLastResetTxt = new Text2('Time Since Last Reset: 0s', { size: 75, fill: "#ffffff" }); timeSinceLastResetTxt.anchor.set(0.5, 0); timeSinceLastResetTxt.y = timeSinceLastRollTxt.y + timeSinceLastRollTxt.height + 20; // Position time since last reset text below time since last roll text LK.gui.top.addChild(timeSinceLastResetTxt); // Create prizes won text var prizesWonTxt = new Text2('Prizes Won:\nBear = 10: 0\nRose = 20: 0\nChoc = 30: 0\nSnake = 40: 0\nClaw = 50: 0\nHat = 60: 0', { size: 50, fill: "#ff0000" }); prizesWonTxt.anchor.set(0.5, 0); prizesWonTxt.y = 2732 - 100; // Position prizes won text at the bottom of the screen prizesWonTxt.y = timeSinceLastResetTxt.y + timeSinceLastResetTxt.height + 20; // Position prizes won text below time since last reset text LK.gui.top.addChild(prizesWonTxt); // Add Prize Box asset directly above roll and reset buttons var prizeBox = LK.getAsset('prizeBox', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 - 400 // Position prize box directly above roll and reset buttons }); game.addChild(prizeBox); // Create roll button var rollButton = LK.getAsset('button', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2 - 200, y: 2732 - 200 }); var rollButtonText = new Text2('Roll', { size: 50, fill: "#ffffff" }); rollButtonText.anchor.set(0.5, 0.5); rollButton.addChild(rollButtonText); game.addChild(rollButton); // Create reset button var resetButton = LK.getAsset('button', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2 + 200, y: 2732 - 200 }); var resetButtonText = new Text2('Reset', { size: 50, fill: "#ffffff" }); resetButtonText.anchor.set(0.5, 0.5); resetButton.addChild(resetButtonText); game.addChild(resetButton); // Create dice var dice = new Dice(); dice.x = 2048 / 2; dice.y = 2732 / 2; game.addChild(dice); // Roll button event rollButton.down = function (x, y, obj) { dice.roll(); scoreTxt.setText('Dice Side: ' + dice.value); var cashWon = dice.value * 10; currentCash += cashWon; totalCashWon += cashWon; cashTxt.setText('Cash Won: ' + cashWon); currentCashTxt.setText('Current Cash: ' + currentCash); totalCashTxt.setText('Total Cash: ' + totalCashWon); timesRolled++; timesRolledTxt.setText('Times Rolled: ' + timesRolled); if (typeof localStorage !== 'undefined') { localStorage.setItem('timesRolled', timesRolled); } // Reset time since last roll timeSinceLastRoll = 0; // Increase Bear prize count if dice side is 1 if (dice.value === 1) { bearPrizesWon += 1; console.log('Bear Prizes Won: ' + bearPrizesWon); // Update Bear prize count var bearPrizeText = prizesWonTxt.text ? prizesWonTxt.text.split('\n') : []; bearPrizeText[1] = 'Bear = 10: ' + bearPrizesWon; prizesWonTxt.setText(bearPrizeText.join('\n')); } // Increase Rose prize count if dice side is 2 if (dice.value === 2) { rosePrizesWon += 1; console.log('Rose Prizes Won: ' + rosePrizesWon); // Update Rose prize count var rosePrizeText = prizesWonTxt.text ? prizesWonTxt.text.split('\n') : []; rosePrizeText[2] = 'Rose = 20: ' + rosePrizesWon; prizesWonTxt.setText(rosePrizeText.join('\n')); } // Increase Choc prize count if dice side is 3 if (dice.value === 3) { chocPrizesWon += 1; console.log('Choc Prizes Won: ' + chocPrizesWon); // Update Choc prize count var chocPrizeText = prizesWonTxt.text ? prizesWonTxt.text.split('\n') : []; chocPrizeText[3] = 'Choc = 30: ' + chocPrizesWon; prizesWonTxt.setText(chocPrizeText.join('\n')); } // Increase Snake prize count if dice side is 4 if (dice.value === 4) { snakePrizesWon += 1; console.log('Snake Prizes Won: ' + snakePrizesWon); // Update Snake prize count var snakePrizeText = prizesWonTxt.text ? prizesWonTxt.text.split('\n') : []; snakePrizeText[4] = 'Snake = 40: ' + snakePrizesWon; prizesWonTxt.setText(snakePrizeText.join('\n')); } // Increase Claw prize count if dice side is 5 if (dice.value === 5) { clawPrizesWon += 1; console.log('Claw Prizes Won: ' + clawPrizesWon); // Update Claw prize count var clawPrizeText = prizesWonTxt.text ? prizesWonTxt.text.split('\n') : []; clawPrizeText[5] = 'Claw = 50: ' + clawPrizesWon; prizesWonTxt.setText(clawPrizeText.join('\n')); } // Increase Hat prize count if dice side is 6 if (dice.value === 6) { hatPrizesWon += 1; console.log('Hat Prizes Won: ' + hatPrizesWon); // Update Hat prize count var hatPrizeText = prizesWonTxt.text ? prizesWonTxt.text.split('\n') : []; hatPrizeText[6] = 'Hat = 60: ' + hatPrizesWon; prizesWonTxt.setText(hatPrizeText.join('\n')); } if (typeof localStorage !== 'undefined') { localStorage.setItem('timesRolled', timesRolled); if (typeof localStorage !== 'undefined') { if (typeof localStorage !== 'undefined') { if (typeof localStorage !== 'undefined' && localStorage.getItem('timesRolled') !== null) { if (typeof localStorage !== 'undefined' && localStorage.getItem('timesRolled') !== null) { if (typeof localStorage !== 'undefined' && localStorage.getItem('timesRolled') !== null) { timesRolled = typeof localStorage !== 'undefined' && localStorage.getItem('timesRolled') !== null ? parseInt(localStorage.getItem('timesRolled')) : 0; } else { timesRolled = 0; } } else { timesRolled = 0; } } else { timesRolled = 0; } } } timesRolledTxt.setText('Times Rolled: ' + timesRolled); } }; // Reset button event resetButton.down = function (x, y, obj) { currentCash = 0; scoreTxt.setText('Dice Side: 1'); cashTxt.setText('Cash Won: 0'); currentCashTxt.setText('Current Cash: ' + currentCash); totalTimeTxt.setText('Total Time: ' + totalTime + 's'); currentTime = 0; currentTimeTxt.setText('Current Time: ' + currentTime + 's'); timesRolledTxt.setText('Times Rolled: ' + timesRolled); if (typeof localStorage !== 'undefined') { localStorage.setItem('timesRolled', timesRolled); } timesReset++; timesResetTxt.setText('Times Reset: ' + timesReset); if (typeof localStorage !== 'undefined') { localStorage.setItem('timesReset', timesReset); timeSinceLastReset++; var timeSinceLastResetDays = Math.floor(timeSinceLastReset / 86400); var timeSinceLastResetHours = Math.floor(timeSinceLastReset % 86400 / 3600); var timeSinceLastResetMinutes = Math.floor(timeSinceLastReset % 3600 / 60); var timeSinceLastResetSeconds = timeSinceLastReset % 60; timeSinceLastResetTxt.setText("Time Since Last Reset: ".concat(timeSinceLastResetDays, "d ").concat(timeSinceLastResetHours, "h ").concat(timeSinceLastResetMinutes, "m ").concat(timeSinceLastResetSeconds, "s")); } // Reset time since last reset timeSinceLastReset++; var timeSinceLastResetDays = Math.floor(timeSinceLastReset / 86400); var timeSinceLastResetHours = Math.floor(timeSinceLastReset % 86400 / 3600); var timeSinceLastResetMinutes = Math.floor(timeSinceLastReset % 3600 / 60); var timeSinceLastResetSeconds = timeSinceLastReset % 60; timeSinceLastResetTxt.setText("Time Since Last Reset: ".concat(timeSinceLastResetDays, "d ").concat(timeSinceLastResetHours, "h ").concat(timeSinceLastResetMinutes, "m ").concat(timeSinceLastResetSeconds, "s")); timeSinceLastReset = 0; clearInterval(timeSinceLastResetInterval); timeSinceLastResetInterval = LK.setInterval(function () { timeSinceLastReset++; var timeSinceLastResetDays = Math.floor(timeSinceLastReset / 86400); var timeSinceLastResetHours = Math.floor(timeSinceLastReset % 86400 / 3600); var timeSinceLastResetMinutes = Math.floor(timeSinceLastReset % 3600 / 60); var timeSinceLastResetSeconds = timeSinceLastReset % 60; timeSinceLastResetTxt.setText("Time Since Last Reset: ".concat(timeSinceLastResetDays, "d ").concat(timeSinceLastResetHours, "h ").concat(timeSinceLastResetMinutes, "m ").concat(timeSinceLastResetSeconds, "s")); }, 1000); if (typeof localStorage !== 'undefined') { localStorage.setItem('timesReset', timesReset); } if (typeof localStorage !== 'undefined') { localStorage.setItem('totalTime', totalTime); localStorage.setItem('timesRolled', timesRolled); localStorage.setItem('timesReset', timesReset); } // Flash screen brown for 500ms LK.effects.flashScreen(0x8B4513, 500); }; // Game update function game.update = function () { // Any game update logic can go here if (LK.ticks % 60 == 0) { // Update every second (60 ticks per second) totalTime++; var totalDays = Math.floor(totalTime / 86400); var totalHours = Math.floor(totalTime % 86400 / 3600); var totalMinutes = Math.floor(totalTime % 3600 / 60); var totalSeconds = totalTime % 60; totalTimeTxt.setText("Total Time: ".concat(totalDays, "d ").concat(totalHours, "h ").concat(totalMinutes, "m ").concat(totalSeconds, "s")); currentTime++; var currentDays = Math.floor(currentTime / 86400); var currentHours = Math.floor(currentTime % 86400 / 3600); var currentMinutes = Math.floor(currentTime % 3600 / 60); var currentSeconds = currentTime % 60; currentTimeTxt.setText("Current Time: ".concat(currentDays, "d ").concat(currentHours, "h ").concat(currentMinutes, "m ").concat(currentSeconds, "s")); timeSinceLastRoll++; var timeSinceLastRollDays = Math.floor(timeSinceLastRoll / 86400); var timeSinceLastRollHours = Math.floor(timeSinceLastRoll % 86400 / 3600); var timeSinceLastRollMinutes = Math.floor(timeSinceLastRoll % 3600 / 60); var timeSinceLastRollSeconds = timeSinceLastRoll % 60; timeSinceLastRollTxt.setText("Time Since Last Roll: ".concat(timeSinceLastRollDays, "d ").concat(timeSinceLastRollHours, "h ").concat(timeSinceLastRollMinutes, "m ").concat(timeSinceLastRollSeconds, "s")); } }; // Global variable to keep track of total cash won var totalCashWon = 0; // Global variable to keep track of time since last roll var timeSinceLastRoll = 0; // Global variable to keep track of time since last reset var timeSinceLastReset = 0; var timeSinceLastResetInterval; // Global variable to keep track of current cash // Global variable to keep track of current cash var currentCash = 0; // Global variable to keep track of times rolled var timesRolled = 0; if (typeof localStorage !== 'undefined' && localStorage.getItem('timesRolled') !== null) { timesRolled = parseInt(localStorage.getItem('timesRolled')) || 0; } if (typeof localStorage !== 'undefined') { if (typeof localStorage !== 'undefined' && localStorage.getItem('timesRolled') !== null) { timesRolled = parseInt(localStorage.getItem('timesRolled')) || 0; } } // Global variable to keep track of current time var currentTime = 0; // Global variable to keep track of times reset var timesReset = 0; // Global variable to keep track of total time var totalTime = 0; if (typeof localStorage !== 'undefined' && localStorage.getItem('totalTime') !== null) { totalTime = parseInt(localStorage.getItem('totalTime')) || 0; } if (typeof localStorage !== 'undefined' && localStorage.getItem('timesReset') !== null) { timesReset = parseInt(localStorage.getItem('timesReset')) || 0; } timeSinceLastResetInterval = LK.setInterval(function () { timeSinceLastReset++; var timeSinceLastResetDays = Math.floor(timeSinceLastReset / 86400); var timeSinceLastResetHours = Math.floor(timeSinceLastReset % 86400 / 3600); var timeSinceLastResetMinutes = Math.floor(timeSinceLastReset % 3600 / 60); var timeSinceLastResetSeconds = timeSinceLastReset % 60; timeSinceLastResetTxt.setText("Time Since Last Reset: ".concat(timeSinceLastResetDays, "d ").concat(timeSinceLastResetHours, "h ").concat(timeSinceLastResetMinutes, "m ").concat(timeSinceLastResetSeconds, "s")); }, 1000);
===================================================================
--- original.js
+++ change.js
@@ -180,8 +180,11 @@
currentCashTxt.setText('Current Cash: ' + currentCash);
totalCashTxt.setText('Total Cash: ' + totalCashWon);
timesRolled++;
timesRolledTxt.setText('Times Rolled: ' + timesRolled);
+ if (typeof localStorage !== 'undefined') {
+ localStorage.setItem('timesRolled', timesRolled);
+ }
// Reset time since last roll
timeSinceLastRoll = 0;
// Increase Bear prize count if dice side is 1
if (dice.value === 1) {
@@ -267,10 +270,12 @@
currentCashTxt.setText('Current Cash: ' + currentCash);
totalTimeTxt.setText('Total Time: ' + totalTime + 's');
currentTime = 0;
currentTimeTxt.setText('Current Time: ' + currentTime + 's');
- timesRolled = typeof localStorage !== 'undefined' && localStorage.getItem('timesRolled') !== null ? parseInt(localStorage.getItem('timesRolled')) : 0;
timesRolledTxt.setText('Times Rolled: ' + timesRolled);
+ if (typeof localStorage !== 'undefined') {
+ localStorage.setItem('timesRolled', timesRolled);
+ }
timesReset++;
timesResetTxt.setText('Times Reset: ' + timesReset);
if (typeof localStorage !== 'undefined') {
localStorage.setItem('timesReset', timesReset);
@@ -345,8 +350,11 @@
// Global variable to keep track of current cash
var currentCash = 0;
// Global variable to keep track of times rolled
var timesRolled = 0;
+if (typeof localStorage !== 'undefined' && localStorage.getItem('timesRolled') !== null) {
+ timesRolled = parseInt(localStorage.getItem('timesRolled')) || 0;
+}
if (typeof localStorage !== 'undefined') {
if (typeof localStorage !== 'undefined' && localStorage.getItem('timesRolled') !== null) {
timesRolled = parseInt(localStorage.getItem('timesRolled')) || 0;
}