autodidact

Veteran
Veteran
Joined
Nov 13, 2020
Messages
58
Reaction score
38
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
49
Reaction score
42
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
58
Reaction score
38
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
49
Reaction score
42
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
58
Reaction score
38
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 Profile Posts

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,386
Messages
1,089,489
Members
150,115
Latest member
tmar
Top