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;
});
/****
* 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;
// UI Elements
var dialogueBox = null;
var characterPortrait = null;
var choiceButtons = [];
var chapterTitle = 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);
}
// 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
playerChoices.push({
chapter: currentChapter,
scene: currentScene,
choiceId: choice.choiceId
});
storage.playerChoices = playerChoices;
// 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 any animations or continuous effects here
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,424 @@
-/****
+/****
+* 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;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ 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;
+// UI Elements
+var dialogueBox = null;
+var characterPortrait = null;
+var choiceButtons = [];
+var chapterTitle = 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);
+}
+// 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
+ playerChoices.push({
+ chapter: currentChapter,
+ scene: currentScene,
+ choiceId: choice.choiceId
+ });
+ storage.playerChoices = playerChoices;
+ // 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 any animations or continuous effects here
+};
\ No newline at end of file