RPG Maker MV

RPG Maker MV

Trinta Feb 24, 2020 @ 4:03am
[SOLVED] playSe, wait, stopSe?
I'm trying to play multiple sound effects sequentially, for a random amount of time, with the new sound effect cutting off the previous one if necessary, because reasons. The game wants to play them all at once, and no amount of googling and finagling the code has produced the desired result yet.

var soundFile
for (j=0;j<3;j++) {
AudioManager.playSe({name: soundFile, pan: 0, pitch: 100, volume: 100});
$gameMap._interpreter.wait(150);
soundFile=[new file];
}

This produces three sounds being played at the same time, followed by a single game delay of 150 frames.

My desired result is to play sound1, wait 150 frames, play sound2, wait 150 frames, play sound3.

Does anyone know how to accomplish this? Thanks!
Last edited by Trinta; Feb 25, 2020 @ 2:46pm
< >
Showing 1-6 of 6 comments
Caethyril Feb 24, 2020 @ 5:17pm 
The interpreter processes one command at a time. Script is a single command: it'll evaluate, then the interpreter will start waiting. =O

For the effect you're seeking, you could use separate Script commands, e.g.
◆Play SE:Sound1 (20, 100, 0) ◆Script:var time = 50 + Math.randomInt(101); // 50~150 frames : :this.wait(time); // random wait before next command ◆Play SE:Sound2 (20, 100, 0) ◆Script:this.wait(50 + Math.randomInt(101)); ◆Script:AudioManager.playSe({ name: "Sound3", pan: 0, pitch: 100, volume: 100 }); ◆Wait:60 frames
I threw in some variation just for demonstration purposes; you'll need script calls for random wait or variable sound properties, otherwise might as well use the event command versions. =)
Trinta Feb 25, 2020 @ 2:57am 
Hey, thanks a ton for the reply!

I guess I wasn't terribly clear, in that I'm trying to do this as a plug-in and not straight-up as an in-game script. However, based on the results I'm seeing, I fear the answer may be the same, and it does explain a bit.

So assuming there isn't a way to force the game to process the plug-in in real-time, it looks like I'm going to making use of a lot of in-game variables. That's cool, though, at least it's a workable solution.

Thanks again! :D
Caethyril Feb 25, 2020 @ 3:57am 
Oh, I see! You probably could rig something with variables etc, but another option is to set up a method to return and insert the appropriate command sequence, kinda like the game does for the Common Event command. E.g.
var MyPlugin = MyPlugin || {}; // Plugin namespace, for neatness (function($) { // In here: $ = MyPlugin 'use strict'; // Utility functions for stuff that gets done more than once $.cPlaySE = function(name, volume) { return {code:250,indent:0,parameters:[{name:name,pan:0,pitch:100,volume:volume}]}; }; $.cWait = function(time) { return {code:230,indent:0,parameters:[time]}; }; $.waitTime = function() { return 50 + Math.randomInt(101); }; $.playMySounds = function(volume) { // Make sure volume is defined volume = volume || 50; // Define list of sound names to play let sounds = ["Thunder1","Thunder2","Thunder3"]; // Initialise command list let list = []; // Populate list sounds.forEach(function(name) { list.push($.cPlaySE(name, volume), $.cWait($.waitTime())); }); // Setup main interpreter (if no event running) or child interpreter (if it is) let interpreter = $gameMap._interpreter; if (interpreter.isRunning()) { let evId = $gameMap._interpreter.eventId(); $gameMap._interpreter.setupChild(list, evId); } else { interpreter.setup(list, 0); } // Interpreter should proceed to execute all commands in list // Then resume the original event }; })(MyPlugin);
Then you can invoke it via script call, or from elsewhere in your plugin, or the console, etc with the following line:
MyPlugin.playMySounds(10);
^ I.e. "play my sounds at 10 volume". Seems to work for me! Obviously this is just an example, you can customise the code as needed for your situation. \o/

Another alternative is to skip the interpreter structure entirely and use something else to schedule the timing, e.g. setTimeout or Promise. I generally recommend sticking with the existing structure, though. ^_^'

In case you're wondering: for the event codes and parameters, I referenced rpg_objects.js (Game_Interpreter, or just search the English name of the event command you're seeking, e.g. "Play SE"). You can also see the event command structure by checking out one of your maps (e.g. Map001.json, assuming it has events on it) in your project's data subfolder. =)
Trinta Feb 25, 2020 @ 4:30am 
Awesome. This looks great. Thanks for being fabulous!
Caethyril Feb 25, 2020 @ 4:50am 
You're welcome! :fhappy:
Trinta Feb 25, 2020 @ 2:46pm 
Successfully made sense of all the things, and was even able to add another command using the codes from rpg_objects that you helpfully included and explained. Working like a charm now! Thanks once again!
Last edited by Trinta; Feb 25, 2020 @ 2:47pm
< >
Showing 1-6 of 6 comments
Per page: 1530 50