Trigger sound effects within a text window

Hi all,

I'm looking for a very specific piece of functionality that I haven't been able to find a plugin for, or figure out a workaround on my own.

I'm using Yanfly's message core, which I know many of us find indispensable for so many reasons. One thing it doesn't allow us to do within gameMessage, is trigger a sound effect.

There does exist the functionality to hit enter within a show text in order to advance, using \!. What I'd like to do is for an additional feature -- whether within YEP or otherwise -- to trigger a sound effect while remaining inside the text window.

Grateful as always for any advice, leads, or help. Also absolutely willing to compensate, though I'm unsure if this is the correct forum for compensated requests.

Thanks in any case!!! :LZScheeze::LZSproud::LZScheeze:
One option:
I have a "custom escape codes" plugin that lets you define your own message codes with some scripting. It has a "play SE" example in its help description so you don't need to figure out the code yourself~ 😮‍💨

Here's a link if you want to check it out: view/download Cae_CustomEscCodes (Google Drive). 🙏
One option:

Caethyril you've always been super helpful, thank you so much! I will try this out and report back :LZSyum:
One option:

Okey doke, I've read over the plugin a bunch, and I believe I can follow how it works. (I'm one of those dilettantes who can follow code reasonably well, and actually create it reasonably terribly). If it's okay with you I'd love to request a tiny bit more handholding in this case :LZSangel:

So in the case of playing a SE, the script you provide is:

var se = {};
se.name = 'Bell1';
se.volume = 20;
se.pitch = 100;
se.pan = 0;
AudioManager.playSe(se);

Seems simple enough. My question then is, where exactly am I defining the escape code? Like let's say I want A\[x] to be my escape code to play a sound effect, and I want to run the above script to play the Bell1 SE with those volume/pitch/pan parameters. Where exactly in the event am I running the above script, and how exactly would I be defining the escape char and pointing to the above script?

Thank you so much for your guidance! I'll be experimenting to try and figure it out on my own in the meantime :LZSyum:
It's OK, this one is kinda advanced! 🙏

All the definitions are done in the plugin parameters in the Plugin Manager. This particular example is a "process" code, because it happens when the message text reaches that point. Double-click the Process Escape Codes parameter, then double-click an empty row to add a new one.

Now you should see four values:
  • Code: type in A.
    This is what the game uses to recognise the escape code. It's like the V in \V[x].

  • Arguments:
    This is a list of possible inputs. \V[x] has one input: the variable ID (an integer).

    1. If you only want to play one type of SE then no arguments are needed.
      You can use it in a message as \A (no brackets needed with no arguments).

    2. Otherwise, you could, for example, have two inputs specifying the SE name and volume.
      In that case you'll need to double-click to add two new entries to the Arguments list:
      • Choose "Text" for the first one (name);
      • Choose "Integer" for the second one (volume).
      Example use in a message: \A[Bell1, 20] (i.e. play Bell1 SE at 20% volume).

    Note that your choice here will affect how the actual script part looks.

  • Delimiters: you can leave this one as [].
    These are just the brackets used to enclose the arguments. 😅

  • Replacer: the actual script part! 👋
    As mentioned in the Arguments section, this may vary if you've included inputs...

    1. With zero arguments, it looks just like the example:
      JavaScript:
      var se = {};
      se.name = 'Bell1';
      se.volume = 20;
      se.pitch = 100;
      se.pan = 0;
      AudioManager.playSe(se);
    2. With two arguments (name and volume), it might look like this:
      JavaScript:
      var se = {};
      se.name = arguments[1];
      se.volume = parseInt(arguments[2], 10);
      se.pitch = 100;
      se.pan = 0;
      AudioManager.playSe(se);
    Hope that makes sense, and if you want something different, just let me know! 😤
Ohhh I think I have a better idea of how this works. I had no idea these were defined in the plugin manager's parameters.

Now that I have an inkling into the functionality of the plugin, it seems to me like for my use case, it makes the most sense to trigger CE's. I'll tell ya why -- what I'm trying to do is trigger voice snippets in the middle of text msgs. I'm using the "wait for player entry" \! escape code in Yanfly, so when the player hits enter/space, the text continues, and ideally an accompanying voice SE.

Since I'll be needing different SE's every time out -- based on how I'm understanding how the plugin works -- it would seem non-ideal to start defining endless SE's since I'll be using different SE's each and every time. Makes a bit more sense to call a CE and manage things that way.

However! I've run into some questions. I'ma take some baby steps here -- first off, what I'm seeing doesn't quite square with what you describe. Here is what I see when I double click on the parameters in plugin manager. First, just to be sure, here's the Gen Settings dialog:

cae_plugin.png


But when I double click on the process escape codes parameter, I only get the single line to enter the escape codes. I'm not using the most up-to-date RPGM (I'm on 1.4.1 to ensure compatibility with some other key plugins), might that make a difference? It seems like by your description, I ought to be presented with multiple rows here, but I've only got the one:

cae_plugin2.png


Given what I'm looking at here, and keeping in mind that calling a different CE in each gameMessage appears to be the best use of the plugin, how might you proceed?

So grateful for your generous attitude Caethyril. You really are the best -- thank you so, so much 😍
Oh, I see! v1.5.0 introduced a revamped Plugin Manager with a bunch of new options, see the screenshot in this thread for an example:
My plugin makes use of lists of structs, so it's very inaccessible to people using older versions of the editor. 😅

Not to worry, though! You just want a "call common event" thing, right? Try copy+pasting this in to the Process Escape Codes text box:
Spoiler: Common event example
JavaScript:
["{\"Code\":\"ce\",\"Arguments\":\"[\\\"Integer\\\"]\",\"Delimiters\":\"[]\",\"Replacer\":\"\\\"var ev = $dataCommonEvents[parseInt(arguments[1], 10)];\\\\nif (ev) {\\\\n  var pt = SceneManager._scene instanceof Scene_Map ?\\\\n           $gameMap._interpreter : $gameTroop._interpreter;\\\\n  var id = pt.isOnCurrentMap() ? pt.eventId() : 0;\\\\n  pt.setupChild(ev.list, id);\\\\n}\\\"\"}"]
This defines a single "process" code for calling a common event mid-text: \CE[n], where n is the ID of the common event to run. Example use in Show Text:
Code:
Welcome! \ce[1]\|Whoa, what was that?
This might not work as expected if used in a Parallel-trigger event, but otherwise should be OK. (I wouldn't recommend using Show Text in parallel anyway.) 😮‍💨

Edit @cuby: actually I just re-read your summary of what you're trying to do and this may be a better option (copy+paste directly into the empty Process Escape Codes text box):
Spoiler: Play sound example
JavaScript:
["{\"Code\":\"se\",\"Arguments\":\"[\\\"Text\\\",\\\"Integer\\\"]\",\"Delimiters\":\"[]\",\"Replacer\":\"\\\"var se = {};\\\\nse.name = arguments[1];\\\\nse.volume = parseInt(arguments[2], 10);\\\\nse.pitch = 100;\\\\nse.pan = 0;\\\\nAudioManager.playSe(se);\\\"\"}"]
Then in a Show Text command you can do something like this:
Code:
\se[Bob1, 20]Welcome to the inn!\!
\se[Bob2, 30]Here for a room?
I.e. play SE "Bob1" at 20% volume, show "Welcome to the inn!", wait for player input, play SE "Bob2" at 30% volume, then show "Here for a room?". That way there's no need to define some kind of complicated system of common events. 🙂

(Also, an aside: \! is a default RPG Maker escape code; you can hover over the Show Text entry box in the editor to see all the default codes.)
Not to worry, though! You just want a "call common event" thing, right? Try copy+pasting this in to the Process Escape Codes text box:
Spoiler: Common event example
JavaScript:
["{\"Code\":\"ce\",\"Arguments\":\"[\\\"Integer\\\"]\",\"Delimiters\":\"[]\",\"Replacer\":\"\\\"var ev = $dataCommonEvents[parseInt(arguments[1], 10)];\\\\nif (ev) {\\\\n  var pt = SceneManager._scene instanceof Scene_Map ?\\\\n           $gameMap._interpreter : $gameTroop._interpreter;\\\\n  var id = pt.isOnCurrentMap() ? pt.eventId() : 0;\\\\n  pt.setupChild(ev.list, id);\\\\n}\\\"\"}"]

@caethyril not only does this work, it works BEAUTIFULLY. I am beyond floored.

This was a functionality that had me banging my head against a wall on and off for monnnnttthhhss. I had already made plans to work around it with all sorts of time-consuming bodges and sub-optimal half-solutions. And here you are with a gorgeous solution that even takes into account my old version of MV. Seriously, thank you so much, I'm so grateful for the time you've taken to help. You totally rock.

Please mark as not only solved, but solved spectacularly :LZSkiss::LZSkiss::LZSkiss::LZSkiss::LZSkiss:
It's OK, this one is kinda advanced! 🙏

All the definitions are done in the plugin parameters in the Plugin Manager. This particular example is a "process" code, because it happens when the message text reaches that point. Double-click the Process Escape Codes parameter, then double-click an empty row to add a new one.

Now you should see four values:
  • Code: type in A.
    This is what the game uses to recognise the escape code. It's like the V in \V[x].

  • Arguments:
    This is a list of possible inputs. \V[x] has one input: the variable ID (an integer).
    1. If you only want to play one type of SE then no arguments are needed.
      You can use it in a message as \A (no brackets needed with no arguments).

    2. Otherwise, you could, for example, have two inputs specifying the SE name and volume.
      In that case you'll need to double-click to add two new entries to the Arguments list:
      • Choose "Text" for the first one (name);
      • Choose "Integer" for the second one (volume).
      Example use in a message: \A[Bell1, 20] (i.e. play Bell1 SE at 20% volume).

    Note that your choice here will affect how the actual script part looks.

  • Delimiters: you can leave this one as [].
    These are just the brackets used to enclose the arguments. 😅

  • Replacer: the actual script part! 👋
    As mentioned in the Arguments section, this may vary if you've included inputs...
    1. With zero arguments, it looks just like the example:
      JavaScript:
      var se = {};
      se.name = 'Bell1';
      se.volume = 20;
      se.pitch = 100;
      se.pan = 0;
      AudioManager.playSe(se);
    2. With two arguments (name and volume), it might look like this:
      JavaScript:
      var se = {};
      se.name = arguments[1];
      se.volume = parseInt(arguments[2], 10);
      se.pitch = 100;
      se.pan = 0;
      AudioManager.playSe(se);
    Hope that makes sense, and if you want something different, just let me know!
Is there a way to change the pitch when using a Sound Effect text code?
Is there a way to change the pitch when using a Sound Effect text code?
Yes! You can add a third argument, type "Integer", then change this line in my previous example:
JavaScript:
se.pitch = 100;
...to this:
JavaScript:
se.pitch = parseInt(arguments[3], 10);
Then you'd just need to specify the pitch when you use the text code, e.g.
  • Play "Bell1" SE at 20% volume and 50% pitch: \A[Bell1, 20, 50]
(Also remember to save your project after making Plugin Manager changes otherwise those changes will not be seen during test~)
Yes! You can add a third argument, type "Integer", then change this line in my previous example:
JavaScript:
se.pitch = 100;
...to this:
JavaScript:
se.pitch = parseInt(arguments[3], 10);
Then you'd just need to specify the pitch when you use the text code, e.g.
  • Play "Bell1" SE at 20% volume and 50% pitch: \A[Bell1, 20, 50]
(Also remember to save your project after making Plugin Manager changes otherwise those changes will not be seen during test~)
Thanks! I have another question if you wouldn't mind. Is there a way to put a specified wait command for one of these codes? I was using Yanflys text codes for this but the text sound effect plugin I have still "blips" when I use them. It would be much easier to have a command like \A[Wait, 60] so that the text sound effect wouldn't go off and so the wait time would be specific to my liking.
@cokes1999: yes, check out process code example 3 from the plugin's help section~

If that doesn't work for you then I recommend starting a new thread, since it sounds like your problem is related to the text SE plugin you're using. If the SE plays on Yanfly's text codes then I imagine it will play on mine, too. (It also sounds like your use case may be different to that of the original poster of this thread. 😴)
@cokes1999: yes, check out process code example 3 from the plugin's help section~

If that doesn't work for you then I recommend starting a new thread, since it sounds like your problem is related to the text SE plugin you're using. If the SE plays on Yanfly's text codes then I imagine it will play on mine, too. (It also sounds like your use case may be different to that of the original poster of this thread. 😴)
Thanks for responding 🙂
For some reason the wait code isn't working at all...... am I doing something wrong?
Do you have text after the wait code? I don't think the wait function ignores player input, so if it's the last thing in that message they'll be able to hit Enter to dismiss the box normally. Could be wrong.

Have you tried the timing codes built into MV? There's \| for a second-long wait. Compare that to the code you made, see if they work differently.
Do you have text after the wait code? I don't think the wait function ignores player input, so if it's the last thing in that message they'll be able to hit Enter to dismiss the box normally. Could be wrong.

Have you tried the timing codes built into MV? There's \| for a second-long wait. Compare that to the code you made, see if they work differently.
There is no text after the wait code. My intention is to use the timing code \^ to ignore the player input after the wait code but the wait code with this plugin is not working for me so it just ignored the player input too quickly (player is not able to read quick enough).

The timing codes such as \. and \| work but the only reason I am looking for a wait code with this plugin is because when using these timing codes the text sound effects still go off. You basically hear a little blip each time you use \| so it doesn't sound right (I'm using Yanfly's Message core and Ext pack). With the text codes that I've used so far with this plugin I haven't had this issue so I'm hoping a wait text code will work.
For some reason the wait code isn't working at all...... am I doing something wrong?
The setup shown in your screenshots works OK for me in a new project with no other plugins active. The default \. and \| codes use exactly the same startWait method. I just checked YEP Message Core and it also uses startWait. By default, wait time applied via startWait does not apply if there is no text remaining in the message.

Note that YEP Message Core:
  • ...cancels any wait time that would otherwise be applied if the action button is being held down at the time (fast-forward mode).
  • ...has its own \w text code that might conflict. I recommend using the one from Message Core anyway: it ends up functionally identical to the one from my plugin.
I'm guessing your "text SE" plugin is YEP Extended Message Pack 1. If so, note that it has codes to turn letter sounds on/off mid-message. Otherwise you can request an alternative plugin or a patch by starting a new thread:
The setup shown in your screenshots works OK for me in a new project with no other plugins active. The default \. and \| codes use exactly the same startWait method. I just checked YEP Message Core and it also uses startWait. By default, wait time applied via startWait does not apply if there is no text remaining in the message.

Note that YEP Message Core:
  • ...cancels any wait time that would otherwise be applied if the action button is being held down at the time (fast-forward mode).
  • ...has its own \w text code that might conflict. I recommend using the one from Message Core anyway: it ends up functionally identical to the one from my plugin.
I'm guessing your "text SE" plugin is YEP Extended Message Pack 1. If so, note that it has codes to turn letter sounds on/off mid-message. Otherwise you can request an alternative plugin or a patch by starting a new thread:
Thank you!!! I'm going to stick with the Yanfly Plugin as turning off the sounds mid-message was the solution. There's so many text codes I basically forgot about that feature.... I feel so stupid lol. Nonetheless, thanks again for you time 🙂

Original thread: https://forums.rpgmakerweb.com/threads/trigger-sound-effects-within-a-text-window.125244/