Hello,
I've used rpg maker in the past and I know javascript, but I'm a total begginer in plugins.
So I'm trying to do a simple plugin where the player has to choose between 3 options and depending on the options a text will appear.
The code looks like this :
Problem is, after I do the choice, and enter the "executeCardAction" function, the $gameMessage.add doesn't show any messages anymore (I tried to do $gameMessage.newPage() but it didn't change anything). And something I don't understand is that I don't get any errors in the console.
Here is the first message:
But when I choose an option, the next message doesn't appear, even tho it enters the function because it does the log:
Do you have any idea where the issue is ?
Thanks in advance
I've used rpg maker in the past and I know javascript, but I'm a total begginer in plugins.
So I'm trying to do a simple plugin where the player has to choose between 3 options and depending on the options a text will appear.
The code looks like this :
JavaScript:
/*:
* @target MZ
* @plugindesc Custom Card Battle System
* @command combat
* @help
* This plugin implements a custom battle system where the player chooses actions from a set of cards.
*/
(() => {
const pluginName = "combat";
class Card {
constructor(name, action, power) {
this.name = name;
this.action = action;
this.power = power;
}
}
const cards = [
new Card("Attack", "attack", 10),
new Card("Heal", "heal", 10),
new Card("Defend", "defend", 5)
];
function startCardBattle() {
$gameMessage.add("A wild enemy appears!");
showCardOptions();
}
function showCardOptions() {
const choices = cards.map(card => card.name);
$gameMessage.setChoices(choices, 0, -1);
$gameMessage.setChoiceCallback(onCardChoice);
$gameMessage.add("Choose a card:");
}
function onCardChoice(choiceIndex) {
const chosenCard = cards[choiceIndex];
executeCardAction(chosenCard);
}
function executeCardAction(card) {
console.log("card: ", card)
$gameMessage.add("testtest");
switch (card.action) {
case "attack":
$gameMessage.add(`You attack the enemy for ${card.power} damage!`);
break;
case "heal":
$gameMessage.add(`You heal yourself for ${card.power} HP!`);
break;
case "defend":
$gameMessage.add(`You defend yourself, reducing damage by ${card.power}.`);
break;
}
}
PluginManager.registerCommand(pluginName, "combat", () => {
startCardBattle();
});
})();
Problem is, after I do the choice, and enter the "executeCardAction" function, the $gameMessage.add doesn't show any messages anymore (I tried to do $gameMessage.newPage() but it didn't change anything). And something I don't understand is that I don't get any errors in the console.
Here is the first message:
But when I choose an option, the next message doesn't appear, even tho it enters the function because it does the log:
Do you have any idea where the issue is ?
Thanks in advance