autodidact

Veteran
Veteran
Joined
Nov 13, 2020
Messages
64
Reaction score
45
First Language
English
Primarily Uses
RMMV
Hello,

A long while ago, I found out RPG MV games could be played with a controller and I thought, "Wow, that sounds really cool!" Then, I tried it out and found how limited that feature is. Well, I have managed to implement the d-pad, right joy stick, and joy stick button presses to do stuff on input.

My problem right now is trying to make the start menu properly close the menu.


This is my code to open the menu:

JavaScript:
var _sal.inputMapper.menuState = false;

var Alias_Scene_Map_updateMain = Scene_Map.prototype.updateMain;

Scene_Map.prototype.updateMain = function() {
    Alias_Scene_Map_updateMain.call(this);
    
    if (Input.isTriggered('startButton')) {
        if (_sal.inputMapper.menuState == false) { //open main menu
        _sal.inputMapper.menuState = true;
        var soundEffect_toplay = { name: "Skill3", volume: 100, pitch: 110, pan: 0};
        AudioManager.playSe(soundEffect_toplay);
        SceneManager.push(Scene_Menu);
        } else {
        _sal.inputMapper.menuState = false;
        SceneManager.pop();
      }
    } //end if 'startButton' pressed

}


Well, this works to open the menu. But, I want to be able to press the "start" button on the controller to close it. Since I am aliasing Scene_Map.prototype.update my close menu code doesn't seem to run when the menu is open.

Where should I put my code to close the menu, when the menu is already open?
 

JorgeMaker

Veteran
Veteran
Joined
Jan 14, 2020
Messages
57
Reaction score
52
First Language
Português - BR
Primarily Uses
RMMZ
Yes, your code is not working because you are trying to exit the Menu via the Map scene. It turns out that the Map and the Menu are different scenes, they don't happen in parallel.

I haven't tested the code, but this should work:

JavaScript:
Scene_Menu.prototype.update = function() {
    Scene_Base.prototype.update.call(this);
    if (Input.isTriggered('startButton')) this.popScene();
};
 

autodidact

Veteran
Veteran
Joined
Nov 13, 2020
Messages
64
Reaction score
45
First Language
English
Primarily Uses
RMMV
Thank you so much, it works!
Now, I can remap MV's default button to open the menu.

I'd like to keep this as compatible as possible. I see you didn't alias Scene_Menu.prototype.update().
Am I overwriting this function, or is it being created?
 

JorgeMaker

Veteran
Veteran
Joined
Jan 14, 2020
Messages
57
Reaction score
52
First Language
Português - BR
Primarily Uses
RMMZ
I didn't alias the update function of Scene_Menu, because originally it doesn't have any specific function other than what it inherits from the Scene_Base class.
But yes, you can make an alias for it if you are using or are going to use a plugin that adds new functions to the update method.

JavaScript:
(() => {
    var alias_Scene_Menu_update = Scene_Menu.prototype.update;
    Scene_Menu.prototype.update = function() {
        alias_Scene_Menu_update.call(this);
        if (Input.isTriggered('startButton')) this.popScene();
    };
})();
 

autodidact

Veteran
Veteran
Joined
Nov 13, 2020
Messages
64
Reaction score
45
First Language
English
Primarily Uses
RMMV
I see. I figured that was what was happening since I couldn't find an existing update method on Scene_Menu. But since I am still learning about how classes and inheritance work, I wanted to ask.

Thank you for teaching me, I feel like this little knowledge will take me quite aways.
 

Latest Threads

Latest Posts

Latest Profile Posts

I'm so annoyed with myself...I can't get this code to work so it looks like I'm going the plugin route for a problem I should be able to do myself :kaolivid:Great. Now I get to murder save file compatibility. Again.
Can't believe my code from four years ago is still working! Did some expansions, and...
1635194553179.png
In related news, I may have an update for my old Extra status window plugin ready. That is, once I manage to sit down and update the documentation... and the demo project... :kaoswt:
How does one pronounce Godot? I've heard it pronounced a couple of different ways, and I genuinely don't know the proper way.
March 2020 ...
1635188823939.jpeg
... vs October 2021
You look like you had a rough day...Here, have a Baby Panda!

Forum statistics

Threads
116,077
Messages
1,095,555
Members
151,443
Latest member
Xtvback
Top