jjraymonds

Veteran
Veteran
Joined
Feb 1, 2020
Messages
55
Reaction score
5
First Language
English
Primarily Uses
RMMV
Hey everyone!

I'm not sure if this is exactly the right place, but I have been trying to create my own save/load system via eventing. I used the scripts from the Maker MV / MZ Script Call list:

JavaScript:
if (DataManager.loadGame($gameVariables.value (56))) {
    $gamePlayer.reserveTransfer($gameMap.mapId(), $gamePlayer.x, $gamePlayer.y);
    $gamePlayer.requestMapReload();
    SceneManager.goto(Scene_Map);
}
(The variable is determined by the player to select the file they want.)
This works fine, but the save file's audio isn't loaded in with everything else. Am I missing a line here?

Edit: To clarify, if I load the same file via the built in load screen window, the BGM will start playing properly.
 
Last edited:

Dev_With_Coffee

Veteran
Veteran
Joined
Jul 20, 2020
Messages
765
Reaction score
373
First Language
PT-BR
Primarily Uses
RM2k3
Hello!
In the command list itself, there is the command that memorizes the played BGM song. Try this:
JavaScript:
$gameSystem.saveBgm();
JavaScript:
$gameSystem.replayBgm();

If you need something more specific, do the following, save the data of the currently playing song in variables:
Code:
function memorizeAudio(){
        if(AudioManager._bgmBuffer){
            savbgm=[
                AudioManager._currentBgm.name,
                AudioManager._currentBgm.volume,
                AudioManager._currentBgm.pitch,
                AudioManager._currentBgm.pan,
                AudioManager._bgsBuffer.seek()
                ];
        }
}

And when loading the game, play the BGM with the previously recorded data:
Code:
function playMemoBGM(){
    if(typeof(savbgm) == "object"){
                AudioManager.playBgm({ name: savbgm[0], volume: savbgm[1], pitch: savbgm[2], pan: savbgm[3] },savbgm[4]);
                AudioManager._bgmBuffer.fadeIn(AudioManager._replayFadeTime);
                savbgm=false;
            }
}

This is a theory, I can't test it now. It must even memorize where the music left off.

The variable savbgm is just to understand the logic, it must be replaced by the object of the data saved at the time of memorization and loading.
 

jjraymonds

Veteran
Veteran
Joined
Feb 1, 2020
Messages
55
Reaction score
5
First Language
English
Primarily Uses
RMMV
Hmm... trying the first approach I ran into the error below. (even when I avoided scripting and used the actual event commands the same error came up.)

Audio Bug.PNG
The error wouldn't show up until I restarted the application and tried to load, but it seemed like it wasn't properly loading the BGM either way? It seems like the save/replay function only works on temporary data?


As far as the other option, would that be done via a plug-in? (My Java knowledge is really, really barebones) So far I've been doing everything just though the Script Event Commands.
 

Dev_With_Coffee

Veteran
Veteran
Joined
Jul 20, 2020
Messages
765
Reaction score
373
First Language
PT-BR
Primarily Uses
RM2k3
I don't even know where this error may have come from:
linearRampToValueAtTime

In my view you don't really seem to be restoring saved data.
The example I gave was just how to store all the data of a current BGM, in your case it would be necessary to save only the name of the song and call the command that reproduces the sound.

Since you didn't really show how to save the data I don't have much to explain.

Good luck
 

jjraymonds

Veteran
Veteran
Joined
Feb 1, 2020
Messages
55
Reaction score
5
First Language
English
Primarily Uses
RMMV
I don't even know where this error may have come from:
linearRampToValueAtTime

In my view you don't really seem to be restoring saved data.
The example I gave was just how to store all the data of a current BGM, in your case it would be necessary to save only the name of the song and call the command that reproduces the sound.

Since you didn't really show how to save the data I don't have much to explain.

Good luck
I was saving the audio data with the first two scripts you suggested, and then I also tried via the equivalent event commands on page 2:

Code:
$gameSystem.saveBgm();
and
Code:
$gameSystem.replayBgm();

or these:
1624400924795.png

The saving of the actual file is this (which I also got from the master script call list, Linked Here)

Code:
$gameSystem.onBeforeSave();
if (DataManager.saveGame(6)) {
  StorageManager.cleanBackup(6);
}

Which I put straight into an event window:
1624400391008.png

sorry for not including how I was originally saving, at my current point during playtesting I've been using the default built in save window mainly for that. Running this script and then trying to load a file though the default built in load menu works totally fine.

As far as the other method you suggested, I asked if that code would have to be used in a plug in because simply dragging and dropping it into a script input like this doesn't seem to work.

1624400485289.png
1624400508454.png
 

Dev_With_Coffee

Veteran
Veteran
Joined
Jul 20, 2020
Messages
765
Reaction score
373
First Language
PT-BR
Primarily Uses
RM2k3
We have 3 problems here :LZYshock: .
  • First you literally used the demo I gave you, this would be functional only as a Plugin.

  • Second, I didn't pass commands but functions, to be executed inside the event command:

    Only:
    memorizeAudio()

    Only:
    playMemoBGM()

  • Java is different from Javascript.
I'll explain how to use a function.
First you create it:
JavaScript:
function MyFirstFunction(){
    alert("Hello world!");
}

And to call it:
JavaScript:
MyFirstFunction()

Function with parameters:
JavaScript:
function MyFirstFunction(name){
    alert("Your name are "+name);
}

And to call it:
JavaScript:
MyFirstFunction("Michael")

Good luck
 

jjraymonds

Veteran
Veteran
Joined
Feb 1, 2020
Messages
55
Reaction score
5
First Language
English
Primarily Uses
RMMV
Ah, yeah- that's why I asked if that was for a plug-in, because I thought it would be! :LZSlol:

Maybe it can't be done... but I would think this should be doable with just a script call from the event menu.

When I was digging through the rpg_scenes.js to see where they were getting the script from I see it came from here. (With an added line I think to check to see if the map has changed in an update?) Again though... I really don't know a lot of coding so I could possibly just be looking in all the wrong directions.

Code:
//-----------------------------------------------------------------------------
// Scene_Load
//
// The scene class of the load screen.

function Scene_Load() {
    this.initialize.apply(this, arguments);
}

Scene_Load.prototype = Object.create(Scene_File.prototype);
Scene_Load.prototype.constructor = Scene_Load;

Scene_Load.prototype.initialize = function() {
    Scene_File.prototype.initialize.call(this);
    this._loadSuccess = false;
};

Scene_Load.prototype.terminate = function() {
    Scene_File.prototype.terminate.call(this);
    if (this._loadSuccess) {
        $gameSystem.onAfterLoad();
    }
};

Scene_Load.prototype.mode = function() {
    return 'load';
};

Scene_Load.prototype.helpWindowText = function() {
    return TextManager.loadMessage;
};

Scene_Load.prototype.firstSavefileIndex = function() {
    return DataManager.latestSavefileId() - 1;
};

Scene_Load.prototype.onSavefileOk = function() {
    Scene_File.prototype.onSavefileOk.call(this);
    if (DataManager.loadGame(this.savefileId())) {
        this.onLoadSuccess();
    } else {
        this.onLoadFailure();
    }
};

Scene_Load.prototype.onLoadSuccess = function() {
    SoundManager.playLoad();
    this.fadeOutAll();
    this.reloadMapIfUpdated();
    SceneManager.goto(Scene_Map);
    this._loadSuccess = true;
};

Scene_Load.prototype.onLoadFailure = function() {
    SoundManager.playBuzzer();
    this.activateListWindow();
};

Scene_Load.prototype.reloadMapIfUpdated = function() {
    if ($gameSystem.versionId() !== $dataSystem.versionId) {
        $gamePlayer.reserveTransfer($gameMap.mapId(), $gamePlayer.x, $gamePlayer.y);
        $gamePlayer.requestMapReload();
    }
};
 

Dev_With_Coffee

Veteran
Veteran
Joined
Jul 20, 2020
Messages
765
Reaction score
373
First Language
PT-BR
Primarily Uses
RM2k3
But you can call, but you would have to write everything inside the function for each situation, for example:
Save:
Code:
if(AudioManager._bgmBuffer){
    savbgm=AudioManager._currentBgm.name
}else{
    savbgm=false;
}

Loading:
JavaScript:
if(typeof(savbgm) == "object"){
    AudioManager.playBgm({name: savbgm, volume: 100, pitch: 100, pan: 0});
}

Name: String filename without extension
Volume: 0~100 (Default -> 100)
Pitch: 50~150 (Default -> 100)
Pan: -100~100 (Default -> 0)

Note:
AudioManager._bgmBuffer is to save the song if it's playing, if you don't use the game it goes to the error screen.
 
Last edited:

jjraymonds

Veteran
Veteran
Joined
Feb 1, 2020
Messages
55
Reaction score
5
First Language
English
Primarily Uses
RMMV
Is that something that would be put in the rpg_scenes.js file? Setting up functions wouldn't work in the script call right? Or do you mean, everytime I open up a new call I would have to have those lines of code at the start? To be clear, every time I say script call- I mean this eventing option:

1624405826800.png
 

Dev_With_Coffee

Veteran
Veteran
Joined
Jul 20, 2020
Messages
765
Reaction score
373
First Language
PT-BR
Primarily Uses
RM2k3
See that I already posted how to use the commands without the functions.
But you will need to replace the savbgm variable with the data that will store this.
:kaosigh:
 

jjraymonds

Veteran
Veteran
Joined
Feb 1, 2020
Messages
55
Reaction score
5
First Language
English
Primarily Uses
RMMV
So setting it up something like this should work? I just want to make sure I'm on the right page. (yes, I would still need to put a variable in- would that be the usual $gameVariables.value()?)

1624407962372.png
 

Dev_With_Coffee

Veteran
Veteran
Joined
Jul 20, 2020
Messages
765
Reaction score
373
First Language
PT-BR
Primarily Uses
RM2k3
To be honest, so far I haven't understood what you're saving on Slot.
The savbgm variable as I said was just for understanding, nowhere in the code did you include it in the data to be saved.

I will try to be clearer, this command only stores the BGM that is playing in a temporary variable, you should just adapt it in the method you write to write the data.

For today I can't help anymore.
Good luck
 

jjraymonds

Veteran
Veteran
Joined
Feb 1, 2020
Messages
55
Reaction score
5
First Language
English
Primarily Uses
RMMV
I'm saving and loading the game's save files, as the script call is listed in that master list.
 

Dev_With_Coffee

Veteran
Veteran
Joined
Jul 20, 2020
Messages
765
Reaction score
373
First Language
PT-BR
Primarily Uses
RM2k3
Excuse me.
I misinterpreted the method you are using, I will test it.
It may be that these examples are more allegorical than actually how they should be used.

Try this:
 

jjraymonds

Veteran
Veteran
Joined
Feb 1, 2020
Messages
55
Reaction score
5
First Language
English
Primarily Uses
RMMV
Using a variable to keep track of what music/background sounds are playing, and then using a common event to check those and play the right audio could be a decent work around... I'm going to ask around in a couple other places too, and use that as my plan B!
 

jjraymonds

Veteran
Veteran
Joined
Feb 1, 2020
Messages
55
Reaction score
5
First Language
English
Primarily Uses
RMMV
Ok, after doing some more digging around I think I found a solution here. Unfortunately this seems to conflict with a plug-in I'd like to use, but I'll follow up with the plug-in dev for that!

EDIT:

Ok so the problem all along was that I was missing a line of code- just as I originally thought! The full script should be something like this: (Note the $gameSystem.onAfterLoad())

Code:
if (DataManager.loadGame(6)) {
    $gamePlayer.reserveTransfer($gameMap.mapId(), $gamePlayer.x, $gamePlayer.y);
    $gamePlayer.requestMapReload();
    SceneManager.goto(Scene_Map);
    $gameSystem.onAfterLoad();
}
 
Last edited:

Latest Threads

Latest Profile Posts

gotta love when a plugin you thought had nothing to do with why something else wasn't working winds up being the issue...
Doing RPG Maker News for 26th September 2021

Well... it's been a while since I was last here :kaoswt: I don't want to say I'm officially 'back' yet, but I've recently started working with RM again, so I might become active here again :kaohi:
Mmmm I love Coca Cola candy! :kaoluv:
aaaand my power is out. I sometimes think that I'm cursed.

Forum statistics

Threads
115,392
Messages
1,089,533
Members
150,124
Latest member
galenus_3d
Top