Creating SE function to play from subfolders (Solved)

I’ve found that it is impossible to play an audio file from inside a subfolder of ‘bgm’, ‘se’ or ‘me’, because the playBgm, playSe and playMe functions are defined in such a way that the files must necessarily be there. Veteran member Shaz says that
(...) AudioManager.playSe uses the se folder.

If you want another folder, you're going to have to create duplicate functions to all the SE functions in AudioManager and tell it to use the path you want, and then you call your new function instead of playSe.
What I’d like to know is if it would be possible to define such duplicate functions (to all the SE functions) in a way that you could choose the folder where the audio file is found on a case by case basis.

I’m just starting to get a hang of Javascript, but by the look of it, it seems like in the following portion, for example, one would have to change ‘se’ to some string variable that can be later accessed and modified from within the game.
Code:
AudioManager.playSe = function(se) {
if (se.name) {
this._seBuffers = this._seBuffers.filter(function(audio) {
return audio.isPlaying();
});
var buffer = this.createBuffer('se', se.name);
this.updateSeParameters(buffer, se);
buffer.play(false);
this._seBuffers.push(buffer);
}
};
How right or wrong am I?
I believe that would work, yes! 🙂

Personally, since it stands a better chance of being compatible with other plugins, I think I'd swap out the folder name in the createBuffer method via an alias instead, e.g. (untested):
Spoiler: Starter example
Code:
(function(alias) {
  var replaceFolder = function(folder) {
    switch (folder) {
      case 'se': return /* your se var */;
      case 'me': return /* your me var */;
      //etc
      default: return folder;
    }
  };

  AudioManager.createBuffer = function(folder, name) {
    folder = replaceFolder(folder);
    return alias.call(this, folder, name);
  };
})(AudioManager.createBuffer);
Or, easier yet, forgo the plugin idea entirely and simply use prefixes/suffixes for your audio file names as appropriate. Feel free to approach it however you like, though~ 🙏
Thanks, Caethyril! It worked! (The untested alias strategy, I mean. It is now tested. The suffix/prefix apporach would obviously work as well).

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/creating-se-function-to-play-from-subfolders-solved.115050/