User prompt
Please fix the bug: 'Script error.' in or related to this line: 'storage.playerChoices = playerChoices;' Line Number: 611 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Give a store to buy new equipment and characters ↪💡 Consider importing and using the following plugins: @upit/storage.v1
Code edit (1 edits merged)
Please save this source code
User prompt
Anime Quest Chronicles
Initial prompt
Anime story type.
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1"); /**** * Classes ****/ var CharacterPortrait = Container.expand(function () { var self = Container.call(this); var portraitBackground = self.attachAsset('characterPortrait', { anchorX: 0.5, anchorY: 0.5 }); var characterName = new Text2('', { size: 32, fill: 0xFFFFFF }); characterName.anchor.set(0.5, 0.5); characterName.y = -150; self.addChild(characterName); self.setCharacter = function (name, color) { characterName.setText(name); portraitBackground.tint = color; }; self.show = function () { self.alpha = 0; self.visible = true; self.scaleX = 0.7; self.scaleY = 0.7; tween(self, { alpha: 1, scaleX: 1, scaleY: 1 }, { duration: 600 }); }; self.hide = function () { tween(self, { alpha: 0 }, { duration: 300, onFinish: function onFinish() { self.visible = false; } }); }; return self; }); var ChoiceButton = Container.expand(function () { var self = Container.call(this); var buttonBackground = self.attachAsset('choiceButton', { anchorX: 0.5, anchorY: 0.5 }); var buttonText = new Text2('', { size: 36, fill: 0xFFFFFF, wordWrap: true, wordWrapWidth: 1500 }); buttonText.anchor.set(0.5, 0.5); self.addChild(buttonText); self.choiceIndex = 0; self.isHovered = false; self.setText = function (text) { buttonText.setText(text); }; self.setChoiceIndex = function (index) { self.choiceIndex = index; }; self.down = function (x, y, obj) { if (currentStoryState === 'waiting_for_choice') { LK.getSound('choice').play(); makeChoice(self.choiceIndex); } }; self.show = function () { self.alpha = 0; self.visible = true; self.scaleX = 0.8; self.scaleY = 0.8; tween(self, { alpha: 1, scaleX: 1, scaleY: 1 }, { duration: 400 }); }; self.hide = function () { tween(self, { alpha: 0, scaleX: 0.8, scaleY: 0.8 }, { duration: 200, onFinish: function onFinish() { self.visible = false; } }); }; return self; }); var DialogueBox = Container.expand(function () { var self = Container.call(this); var dialogueBackground = self.attachAsset('dialogueBox', { anchorX: 0.5, anchorY: 0.5 }); var dialogueText = new Text2('', { size: 40, fill: 0xFFFFFF, wordWrap: true, wordWrapWidth: 1700 }); dialogueText.anchor.set(0.5, 0.5); self.addChild(dialogueText); self.setText = function (text) { dialogueText.setText(text); }; self.show = function () { self.alpha = 0; self.visible = true; tween(self, { alpha: 1 }, { duration: 500 }); }; self.hide = function () { tween(self, { alpha: 0 }, { duration: 300, onFinish: function onFinish() { self.visible = false; } }); }; return self; }); var Store = Container.expand(function () { var self = Container.call(this); var storePanel = self.attachAsset('storePanel', { anchorX: 0.5, anchorY: 0.5 }); var titleText = new Text2('ANIME STORE', { size: 48, fill: 0xf39c12 }); titleText.anchor.set(0.5, 0.5); titleText.y = -1000; self.addChild(titleText); var coinsText = new Text2('', { size: 36, fill: 0xFFFFFF }); coinsText.anchor.set(0.5, 0.5); coinsText.y = -900; self.addChild(coinsText); var closeButton = self.attachAsset('closeButton', { anchorX: 0.5, anchorY: 0.5, x: 700, y: -1000 }); var closeText = new Text2('X', { size: 32, fill: 0xFFFFFF }); closeText.anchor.set(0.5, 0.5); closeText.x = 700; closeText.y = -1000; self.addChild(closeText); var storeItems = []; var itemData = [{ name: 'Magic Sword', price: 100, type: 'equipment', description: 'Increases story options' }, { name: 'Healing Potion', price: 50, type: 'equipment', description: 'Allows retry of choices' }, { name: 'Mystic Character', price: 200, type: 'character', description: 'Unlocks new story paths' }, { name: 'Fire Mage', price: 300, type: 'character', description: 'Special dialogue options' }, { name: 'Shadow Cloak', price: 150, type: 'equipment', description: 'Access to secret scenes' }]; for (var i = 0; i < itemData.length; i++) { var item = new Container(); var itemBg = item.attachAsset('storeItem', { anchorX: 0.5, anchorY: 0.5 }); var itemName = new Text2(itemData[i].name, { size: 32, fill: 0xFFFFFF }); itemName.anchor.set(0, 0.5); itemName.x = -680; itemName.y = -20; item.addChild(itemName); var itemDesc = new Text2(itemData[i].description, { size: 24, fill: 0xbdc3c7 }); itemDesc.anchor.set(0, 0.5); itemDesc.x = -680; itemDesc.y = 20; item.addChild(itemDesc); var buyButton = item.attachAsset('buyButton', { anchorX: 0.5, anchorY: 0.5, x: 500 }); var priceText = new Text2(itemData[i].price + ' coins', { size: 28, fill: 0xFFFFFF }); priceText.anchor.set(0.5, 0.5); priceText.x = 500; item.addChild(priceText); item.y = -600 + i * 180; item.itemData = itemData[i]; item.itemIndex = i; item.down = function (x, y, obj) { var clickedItem = obj.parent; purchaseItem(clickedItem.itemData, clickedItem.itemIndex); }; storeItems.push(item); self.addChild(item); } closeButton.down = function () { self.hide(); }; self.show = function () { self.visible = true; self.alpha = 0; self.scaleX = 0.8; self.scaleY = 0.8; var coins = storage.coins || 0; coinsText.setText('Coins: ' + coins); tween(self, { alpha: 1, scaleX: 1, scaleY: 1 }, { duration: 500 }); updateStoreItems(); }; self.hide = function () { tween(self, { alpha: 0, scaleX: 0.8, scaleY: 0.8 }, { duration: 300, onFinish: function onFinish() { self.visible = false; } }); }; function updateStoreItems() { var playerInventory = storage.inventory || {}; for (var i = 0; i < storeItems.length; i++) { var item = storeItems[i]; var owned = playerInventory[item.itemData.name] || false; if (owned) { item.children[3].tint = 0x7f8c8d; item.children[3].setText('OWNED'); } } } function purchaseItem(itemData, itemIndex) { var coins = storage.coins || 0; var inventory = storage.inventory || {}; if (inventory[itemData.name]) { return; } if (coins >= itemData.price) { storage.coins = coins - itemData.price; inventory[itemData.name] = true; storage.inventory = inventory; LK.getSound('purchase').play(); coinsText.setText('Coins: ' + storage.coins); updateStoreItems(); } } self.visible = false; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x1a1a2e }); /**** * Game Code ****/ // Game state variables var currentStoryState = 'intro'; var currentChapter = 0; var currentScene = 0; var playerChoices = storage.playerChoices || []; var unlockedChapters = storage.unlockedChapters || [0]; var currentBackground = null; // Initialize coins if not exists if (storage.coins === undefined) { storage.coins = 100; } // UI Elements var dialogueBox = null; var characterPortrait = null; var choiceButtons = []; var chapterTitle = null; var store = null; var storeButton = null; var coinsDisplay = null; // Story data structure var storyData = { chapters: [{ title: "The Mysterious Forest", background: "forest", scenes: [{ character: "Narrator", characterColor: 0x34495e, text: "You find yourself standing at the edge of a mysterious forest. The ancient trees whisper secrets in the wind, and a path disappears into the shadows ahead.", choices: [{ text: "Enter the forest bravely", nextScene: 1, choiceId: "forest_brave" }, { text: "Look for another way around", nextScene: 2, choiceId: "forest_cautious" }, { text: "Call out to see if anyone is there", nextScene: 3, choiceId: "forest_call" }] }, { character: "Forest Spirit", characterColor: 0x27ae60, text: "Your courage impresses the forest spirits. A gentle voice echoes around you: 'Welcome, brave traveler. The path ahead holds great adventure, but also great danger.'", choices: [{ text: "Ask about the danger", nextScene: 4, choiceId: "ask_danger" }, { text: "Thank the spirit and continue", nextScene: 5, choiceId: "continue_brave" }] }, { character: "Old Hermit", characterColor: 0x8e44ad, text: "As you search for another path, you encounter an old hermit. 'The forest is not what it seems, young one. Many paths lead to the same destination, but the journey shapes the soul.'", choices: [{ text: "Ask for guidance", nextScene: 6, choiceId: "ask_guidance" }, { text: "Politely decline and enter the forest", nextScene: 1, choiceId: "decline_enter" }] }, { character: "Echo", characterColor: 0xe67e22, text: "Your voice echoes through the trees, and surprisingly, you hear a response! 'Help... me...' comes a faint cry from deep within the forest.", choices: [{ text: "Rush toward the voice", nextScene: 7, choiceId: "rush_help" }, { text: "Approach carefully", nextScene: 8, choiceId: "careful_help" }] }, { character: "Forest Spirit", characterColor: 0x27ae60, text: "'Dark forces have awakened in the heart of the forest. Ancient magic protects this place, but it weakens. Choose your allies wisely, for the final battle approaches.'", choices: [{ text: "Offer to help restore the magic", nextScene: 9, choiceId: "help_magic" }, { text: "Ask how to find allies", nextScene: 10, choiceId: "find_allies" }] }, { character: "Narrator", characterColor: 0x34495e, text: "You venture deeper into the forest with newfound confidence. The path ahead glows with a mysterious light, leading you toward your destiny.", choices: [{ text: "Continue to Chapter 2", nextScene: -1, choiceId: "continue_chapter2" }] }] }] }; // Initialize UI elements function initializeUI() { // Create dialogue box dialogueBox = new DialogueBox(); dialogueBox.x = game.width / 2; dialogueBox.y = game.height - 250; dialogueBox.visible = false; game.addChild(dialogueBox); // Create character portrait characterPortrait = new CharacterPortrait(); characterPortrait.x = 200; characterPortrait.y = game.height - 400; characterPortrait.visible = false; game.addChild(characterPortrait); // Create choice buttons for (var i = 0; i < 3; i++) { var choiceButton = new ChoiceButton(); choiceButton.x = game.width / 2; choiceButton.y = game.height - 700 + i * 140; choiceButton.visible = false; choiceButtons.push(choiceButton); game.addChild(choiceButton); } // Create chapter title chapterTitle = new Text2('', { size: 60, fill: 0xF39C12 }); chapterTitle.anchor.set(0.5, 0.5); chapterTitle.x = game.width / 2; chapterTitle.y = 200; game.addChild(chapterTitle); // Create store store = new Store(); store.x = game.width / 2; store.y = game.height / 2; game.addChild(store); // Create store button storeButton = LK.getAsset('storeButton', { anchorX: 0.5, anchorY: 0.5, x: game.width - 150, y: 150 }); game.addChild(storeButton); var storeButtonText = new Text2('STORE', { size: 24, fill: 0xFFFFFF }); storeButtonText.anchor.set(0.5, 0.5); storeButtonText.x = game.width - 150; storeButtonText.y = 150; game.addChild(storeButtonText); // Create coins display coinsDisplay = new Text2('', { size: 36, fill: 0xf39c12 }); coinsDisplay.anchor.set(1, 0); coinsDisplay.x = game.width - 20; coinsDisplay.y = 20; game.addChild(coinsDisplay); storeButton.down = function () { store.show(); }; } // Set background based on scene function setBackground(backgroundType) { if (currentBackground) { currentBackground.destroy(); } var backgroundAsset = ''; switch (backgroundType) { case 'forest': backgroundAsset = 'backgroundForest'; break; case 'castle': backgroundAsset = 'backgroundCastle'; break; case 'town': backgroundAsset = 'backgroundTown'; break; default: backgroundAsset = 'backgroundForest'; } currentBackground = LK.getAsset(backgroundAsset, { anchorX: 0, anchorY: 0, x: 0, y: 0 }); game.addChildAt(currentBackground, 0); } // Display current scene function displayScene() { if (currentChapter >= storyData.chapters.length) { showGameComplete(); return; } var chapter = storyData.chapters[currentChapter]; var scene = chapter.scenes[currentScene]; if (!scene) { // Move to next chapter currentChapter++; currentScene = 0; if (currentChapter < storyData.chapters.length) { unlockedChapters.push(currentChapter); storage.unlockedChapters = unlockedChapters; displayScene(); } else { showGameComplete(); } return; } // Set background setBackground(chapter.background); // Show chapter title briefly chapterTitle.setText(chapter.title); chapterTitle.alpha = 1; tween(chapterTitle, { alpha: 0 }, { duration: 2000 }); // Hide all choice buttons for (var i = 0; i < choiceButtons.length; i++) { choiceButtons[i].hide(); } // Show character portrait characterPortrait.setCharacter(scene.character, scene.characterColor); characterPortrait.show(); // Show dialogue dialogueBox.setText(scene.text); dialogueBox.show(); LK.getSound('pageFlip').play(); // Show choices after a delay LK.setTimeout(function () { showChoices(scene.choices); }, 1500); } // Show choice buttons function showChoices(choices) { currentStoryState = 'waiting_for_choice'; for (var i = 0; i < choices.length; i++) { if (i < choiceButtons.length) { choiceButtons[i].setText(choices[i].text); choiceButtons[i].setChoiceIndex(i); choiceButtons[i].show(); } } } // Handle player choice function makeChoice(choiceIndex) { if (currentStoryState !== 'waiting_for_choice') return; currentStoryState = 'transitioning'; var chapter = storyData.chapters[currentChapter]; var scene = chapter.scenes[currentScene]; var choice = scene.choices[choiceIndex]; // Record choice - flatten for storage compatibility var choiceRecord = currentChapter + "_" + currentScene + "_" + choice.choiceId; playerChoices.push(choiceRecord); storage.playerChoices = playerChoices; // Award coins for making choices var coinsEarned = Math.floor(Math.random() * 20) + 10; storage.coins = (storage.coins || 0) + coinsEarned; // Hide UI elements for (var i = 0; i < choiceButtons.length; i++) { choiceButtons[i].hide(); } dialogueBox.hide(); characterPortrait.hide(); // Transition to next scene LK.setTimeout(function () { if (choice.nextScene === -1) { // Move to next chapter currentChapter++; currentScene = 0; } else { currentScene = choice.nextScene; } displayScene(); }, 800); } // Show game completion function showGameComplete() { dialogueBox.setText("Congratulations! You have completed this chapter of your anime adventure. Your choices have shaped your unique story path!"); dialogueBox.show(); characterPortrait.setCharacter("The End", 0xf39c12); characterPortrait.show(); LK.setTimeout(function () { LK.showYouWin(); }, 3000); } // Initialize game initializeUI(); setBackground('forest'); // Start the story LK.setTimeout(function () { displayScene(); }, 1000); // Game update loop game.update = function () { // Update coins display if (coinsDisplay) { coinsDisplay.setText('Coins: ' + (storage.coins || 0)); } // Update any animations or continuous effects here };
===================================================================
--- original.js
+++ change.js
@@ -580,14 +580,11 @@
currentStoryState = 'transitioning';
var chapter = storyData.chapters[currentChapter];
var scene = chapter.scenes[currentScene];
var choice = scene.choices[choiceIndex];
- // Record choice
- playerChoices.push({
- chapter: currentChapter,
- scene: currentScene,
- choiceId: choice.choiceId
- });
+ // Record choice - flatten for storage compatibility
+ var choiceRecord = currentChapter + "_" + currentScene + "_" + choice.choiceId;
+ playerChoices.push(choiceRecord);
storage.playerChoices = playerChoices;
// Award coins for making choices
var coinsEarned = Math.floor(Math.random() * 20) + 10;
storage.coins = (storage.coins || 0) + coinsEarned;