Hi, I searched the forum and found many related threads, but none explained exactly what I wanted to do.
I want to create the event on the map directly inside the editor, but I want to write the event's contents in Javascript, not in a script call but in a separate JS file.
The following is my approach for the Show Text command.
This code is written in a file called customEvents.js
I included this file in the editor just like any plugin through the plugin manager.
I somehow made it work but there are too many commands and the script documentation does not work properly when coding in a separate js file. For example, I tried to use a similar approach for the Show Choices command but it didn't work.
Is there any resources where I can read more about this. Any help will be appreciated. Thanks.
I want to create the event on the map directly inside the editor, but I want to write the event's contents in Javascript, not in a script call but in a separate JS file.
The following is my approach for the Show Text command.
JavaScript:
// Helper function to wait until the message is no longer busy
function waitForMessageCompletion() {
return new Promise(resolve => {
const checkMessageStatus = () => {
if (!$gameMessage.isBusy()) {
resolve();
} else {
setTimeout(checkMessageStatus, 50); // Check again in 50ms
}
};
checkMessageStatus();
});
}
async function displayMessageAsync(message = '', speakerName = '', faceName = '', faceIndex = 0, background = 0, positionType = 2) {
if (message.length > 0) {
$gamePlayer._movementDisabled = true;
if (faceName) {
$gameMessage.setFaceImage(faceName, faceIndex);
}
if (speakerName) {
$gameMessage.setSpeakerName(speakerName);
}
$gameMessage.setBackground(background);
$gameMessage.setPositionType(positionType);
$gameMessage.add(message);
await waitForMessageCompletion(); // Wait until the message is closed
$gamePlayer._movementDisabled = false;
}
}
async function meetRandomBoy(interpreter) {
const event = $gameMap.event(interpreter.eventId);
if (event) {
await displayMessageAsync("You meet a young boy in the new town.", "RandomBoy1", 'People1', 0);
await displayMessageAsync("Boy: Hi there! Welcome to our town!", "RandomBoy1", 'People1', 0);
await displayMessageAsync("Boy: If you need any help, feel free to ask.", "RandomBoy1", 'People1', 0);
} else {
console.error("Event not found: " + interpreter.eventId);
}
}
This code is written in a file called customEvents.js
I included this file in the editor just like any plugin through the plugin manager.
I somehow made it work but there are too many commands and the script documentation does not work properly when coding in a separate js file. For example, I tried to use a similar approach for the Show Choices command but it didn't work.
Is there any resources where I can read more about this. Any help will be appreciated. Thanks.