Hello, first of all I present myself. I'm Zongoyo, I'm a programmer and was looking into RPG Maker MV development for hobby.
I was trying to automatize a conversation, but I'm not being able.
The goal is make a plugin with a random conversation generator, which also includes images, transitions and flashes.
The main difficulty I've found is with transitions and flashes. Text and images work perfectly.
I'd deeply appreciate an example of a plugin with some sentences, and among them some fadeout/wait/fadein and some flashes.
Nothing overly complicated. It's just I can feel I'm not getting the setup or the syntax properly.
I also attach what I've done just in case someone could help me.
This code is executed from a event page. I attach an image.
What is hapening with this code is: it appears the first message, when I click on the screen so it will continue the script execution, the first of the flashes happens, and then it jumps to the message after the script in the event page.
If I comment everything but talk() functions everything works ok. So I think I should need some method to synchronize the execution.
If someone can help me I'll be deeply thankful.
Have a nice week.
I was trying to automatize a conversation, but I'm not being able.
The goal is make a plugin with a random conversation generator, which also includes images, transitions and flashes.
The main difficulty I've found is with transitions and flashes. Text and images work perfectly.
I'd deeply appreciate an example of a plugin with some sentences, and among them some fadeout/wait/fadein and some flashes.
Nothing overly complicated. It's just I can feel I'm not getting the setup or the syntax properly.
I also attach what I've done just in case someone could help me.
JavaScript:
/*:
* @plugindesc Async dialogue system for RPG Maker MV/MZ
* @author Zongoyo
*
* @help
* Use morningTalk() in a script call to start the conversation
* Use beforeDinnerTalk() in a script call to start the conversation
* Use beforeBedTalk() in a script call to start the conversation
* Use bedTalk() in a script call to start the conversation
*/
(() => {
const _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function (command, args) {
_Game_Interpreter_pluginCommand.call(this, command, args);
if (command === 'morningTalk') {
morningTalk.call(this);
} else if (command === 'beforeDinnerTalk') {
beforeDinnerTalk.call(this);
} else if (command === 'beforeBedTalk') {
beforeBedTalk.call(this);
} else if (command === 'bedTalk') {
bedTalk.call(this);
}
};
async function morningTalk() {
console.log('wip');
};
async function beforeDinnerTalk() {
console.log('wip');
};
async function beforeBedTalk() {
console.log('wip');
};
async function bedTalk() {
try {
await talk('Actor1', ['11111111111', '2222222222', '33333333333', '4444444444']);
await makeFlash();
await startTransition();
await endTransition();
await talk('Actor2', ['55555555', '666666666', '777777777', '888888888']);
await showPicture(1, '4');
await talk('Actor2', ['111', '222', '333', '444']);
await hidePicture(1);
await talk('Actor1', ['999', '888', '777', '666']);
} catch (error) {
console.error('Error in bedTalk:', error);
}
};
function talk(face, messages) {
return new Promise((resolve) => {
$gameMessage.clear();
$gameMessage.setFaceImage(face, 0);
$gameMessage.setBackground(0);
$gameMessage.setPositionType(2);
messages.forEach(text => {
if (text !== '') {
$gameMessage.add(text);
}
});
const waitInterval = setInterval(() => {
if (!$gameMessage.isBusy()) {
clearInterval(waitInterval);
resolve();
}
}, 10);
});
};
function showPicture(pictureId, fileName) {
return new Promise((resolve) => {
$gameScreen.showPicture(pictureId, fileName, 0, 0, 0, 100, 100, 255, 0);
setTimeout(() => {
resolve();
}, 1000);
});
};
function hidePicture(pictureId) {
return new Promise((resolve) => {
$gameScreen.erasePicture(pictureId);
setTimeout(() => {
resolve();
}, 1000);
});
};
function makeFlash() {
return new Promise((resolve) => {
$gameScreen.startFlash([255, 255, 255, 255], 30);
setTimeout(() => {
resolve();
}, 1000);
});
};
function startTransition() {
return new Promise((resolve) => {
$gameScreen.startFadeOut(60);
setTimeout(() => {
resolve();
}, 1000);
});
};
function endTransition() {
return new Promise((resolve) => {
$gameScreen.startFadeIn(60);
setTimeout(() => {
resolve();
}, 1000);
});
};
})();
This code is executed from a event page. I attach an image.
What is hapening with this code is: it appears the first message, when I click on the screen so it will continue the script execution, the first of the flashes happens, and then it jumps to the message after the script in the event page.
If I comment everything but talk() functions everything works ok. So I think I should need some method to synchronize the execution.
If someone can help me I'll be deeply thankful.
Have a nice week.