Can't find where menu is called

Hello,


I've been trying to create a menu where it would be displayed with drawn images and work as in one layer (not like the current layered menu)
Even if I think of myself as a pretty decent programmer, I can't where the function of menu screen is called.
I will be very thankful for any help, since I've been stuck on this problem for a while now 😅

Also, side note, is it just me or is the RPG MM MZ code horribly complicated?
I've been trying to create a menu where it would be displayed with drawn images and work as in one layer (not like the current layered menu)
I don't know exactly what you're going for, but you might find it easier to just event it.

Also, side note, is it just me or is the RPG MM MZ code horribly complicated?
Mmm...I don't think so? Obviously, what each person considers to be "complicated" will vary by their individual brains, but I don't really think it's reasonable for someone who's proficient with object-oriented coding to think it's "horribly" complicated 😉

I grepped the word "menu" in the js folder. Immediately I know we can ignore rmmz_scenes, windows, and sprites because those are all going to have to do with how the menu is drawn and navigated, not how it's called by a button press.

So I click into rmmz_core and there are 8 instances of the word "menu" - none of them are calling the menu, although the last two are clearly related as they're defining the "menu" keypress.

So the only other option is rmmz_objects, which has 32 instances of the word "menu". When I get to item 30, that's clearly a hit - it's the event command for opening the menu.
1717707346526.png


At this point, we know one of our assumptions must have been wrong because we've gone through the remaining files and didn't find what we're looking for. But this part gave us the exact syntax to look for!

So I grep SceneManager.push(Scene_Menu) and it comes right up in rmmz_scenes, the callMenu() method of Scene_Map.
1717707501704.png


I don't think this is horribly complicated - it took me less than five minutes, doing all of these steps with typing them out for you and including screenshots. And, of course, since I have some experience with the codebase I know right off the bat that button presses to go between scenes is in rmmz_scenes and that I'd be looking for a push of Scene_Menu.

The question for you is - why do you need this? If you're replacing the default menu with your own, the logical thing would to keep it being of data type Scene_Menu and you just overwrite whichever windows and methods you need to make it look and act the way you like.

I don't see why you'd need to mess with how the menu is opened in the first place at all.
Also, side note, is it just me or is the RPG MM MZ code horribly complicated?
I don't feel that it's particularly complicated. I mean, it's code for an entire game engine, so there's obviously going to be a lot of things that you need to wrap your head around, but (for the most part) there is a rhyme and reason behind how it's all organized.

Probably the three JavaScript files that a plugin developer would use most often are:

  • rmmz_objects.js:
    • This file contains definitions for various game objects, including characters, items, and other data that define the state of the game. It manages the data and the business logic of the game. If you are familiar with the MVC programming design pattern, this could be considered the "Model".
  • rmmz_windows.js:
    • This file deals with the window and user interface components, defining how information is presented to the player. It manages the graphical representation of data and user interaction elements, making it fit the "View" role in MVC.
  • rmmz_scenes.js:
    • This file contains definitions for various scenes in the game, managing the flow of the game and user inputs. It handles user interactions and updates the model and view accordingly. Thus, it acts as the "Controller" in MVC. Everything in the game (the map, battles, menus, etc) is part of a scene, so if you're ever at a loss about how to find the code for something, you can almost always start at the scene and trace your way to where you need to be.
The other potentially relevant files are:

  • rmmz_managers.js:
    • This file includes various static classes that provide functions to help handle different aspects of the game's runtime environment. The classes are all named in a pretty self-descriptive manner. Examples include DataManager, SceneManager, BattleManager, and AudioManager. These managers are responsible for loading data, managing scenes, handling battles, and controlling audio, respectively.
  • rmmz_sprites.js:
    • This file defines classes for handling game sprites, including characters, enemies, and other visual elements. It deals with the graphical representation and animations of these elements, functioning as a detailed part of the view layer in the MVC paradigm.
  • rmmz_core.js:
    • This file contains the core engine functionality and foundational classes that other scripts build upon. It includes basic utility functions, base classes, and essential game system settings. Essentially, it provides the backbone of the engine and underpins the entire system.
As I mentioned previously, everything in the game is part of a scene, so when in doubt, you can almost always start with the code for the relevant scene to trace your way to the code that you're interested in. However, it's often quickest to do what ATT_Turan suggested, and just run a search for relevant terms.

Also, everything is named in a manner that makes it pretty obvious what it is at a glance. For example, there is a class named Game_Message. Without even reading any code, you can probably guess that that class handles messages in the game. That class has a method named setSpeakerName. Without even reading any code, you can probably guess that that method sets the name of the current speaker of a message. As such, if you happen to use Visual Studio Code, the "Outline" window can be pretty handy at helping you quickly comb through a file and/or class for something specific:
1717734882394.png
I don't know exactly what you're going for, but you might find it easier to just event it.


Mmm...I don't think so? Obviously, what each person considers to be "complicated" will vary by their individual brains, but I don't really think it's reasonable for someone who's proficient with object-oriented coding to think it's "horribly" complicated 😉

I grepped the word "menu" in the js folder. Immediately I know we can ignore rmmz_scenes, windows, and sprites because those are all going to have to do with how the menu is drawn and navigated, not how it's called by a button press.

So I click into rmmz_core and there are 8 instances of the word "menu" - none of them are calling the menu, although the last two are clearly related as they're defining the "menu" keypress.

So the only other option is rmmz_objects, which has 32 instances of the word "menu". When I get to item 30, that's clearly a hit - it's the event command for opening the menu.
View attachment 307705

At this point, we know one of our assumptions must have been wrong because we've gone through the remaining files and didn't find what we're looking for. But this part gave us the exact syntax to look for!

So I grep SceneManager.push(Scene_Menu) and it comes right up in rmmz_scenes, the callMenu() method of Scene_Map.
View attachment 307707

I don't think this is horribly complicated - it took me less than five minutes, doing all of these steps with typing them out for you and including screenshots. And, of course, since I have some experience with the codebase I know right off the bat that button presses to go between scenes is in rmmz_scenes and that I'd be looking for a push of Scene_Menu.

The question for you is - why do you need this? If you're replacing the default menu with your own, the logical thing would to keep it being of data type Scene_Menu and you just overwrite whichever windows and methods you need to make it look and act the way you like.

I don't see why you'd need to mess with how the menu is opened in the first place at all.
When you put it that way, then yes, it does seem easy 😀

I guess the most complicated part to me stems from the size of the files. I'm used to files not being longer than 200 lines due to company policy and ease of reading.

As for why I'm trying to learn where the code is called, is because I usually learn a lot better when I follow the execution process. It's just always in the back of my mind, I guess.

Thanks a whole lot, I will look into it further and try out different stuff 😀 It hasn't been too long since I've started and just wanted to get this mystery out of my hair!

I don't feel that it's particularly complicated. I mean, it's code for an entire game engine, so there's obviously going to be a lot of things that you need to wrap your head around, but (for the most part) there is a rhyme and reason behind how it's all organized.

Probably the three JavaScript files that a plugin developer would use most often are:

  • rmmz_objects.js:
    • This file contains definitions for various game objects, including characters, items, and other data that define the state of the game. It manages the data and the business logic of the game. If you are familiar with the MVC programming design pattern, this could be considered the "Model".
  • rmmz_windows.js:
    • This file deals with the window and user interface components, defining how information is presented to the player. It manages the graphical representation of data and user interaction elements, making it fit the "View" role in MVC.
  • rmmz_scenes.js:
    • This file contains definitions for various scenes in the game, managing the flow of the game and user inputs. It handles user interactions and updates the model and view accordingly. Thus, it acts as the "Controller" in MVC. Everything in the game (the map, battles, menus, etc) is part of a scene, so if you're ever at a loss about how to find the code for something, you can almost always start at the scene and trace your way to where you need to be.
The other potentially relevant files are:

  • rmmz_managers.js:
    • This file includes various static classes that provide functions to help handle different aspects of the game's runtime environment. The classes are all named in a pretty self-descriptive manner. Examples include DataManager, SceneManager, BattleManager, and AudioManager. These managers are responsible for loading data, managing scenes, handling battles, and controlling audio, respectively.
  • rmmz_sprites.js:
    • This file defines classes for handling game sprites, including characters, enemies, and other visual elements. It deals with the graphical representation and animations of these elements, functioning as a detailed part of the view layer in the MVC paradigm.
  • rmmz_core.js:
    • This file contains the core engine functionality and foundational classes that other scripts build upon. It includes basic utility functions, base classes, and essential game system settings. Essentially, it provides the backbone of the engine and underpins the entire system.
As I mentioned previously, everything in the game is part of a scene, so when in doubt, you can almost always start with the code for the relevant scene to trace your way to the code that you're interested in. However, it's often quickest to do what ATT_Turan suggested, and just run a search for relevant terms.

Also, everything is named in a manner that makes it pretty obvious what it is at a glance. For example, there is a class named Game_Message. Without even reading any code, you can probably guess that that class handles messages in the game. That class has a method named setSpeakerName. Without even reading any code, you can probably guess that that method sets the name of the current speaker of a message. As such, if you happen to use Visual Studio Code, the "Outline" window can be pretty handy at helping you quickly comb through a file and/or class for something specific:
View attachment 307731
Thank you a whole lot! Yeah, I guess I was just overwhelmed by the size of the files.

I'll take in a whole lot more into consideration 😀 I might have found the location earlier, when I was interested in other code changes, but probably forgot 😅

Thanks once again for entertaining this dumb question 😀
Thank you a whole lot! Yeah, I guess I was just overwhelmed by the size of the files.

I'll take in a whole lot more into consideration 😀 I might have found the location earlier, when I was interested in other code changes, but probably forgot 😅

Thanks once again for entertaining this dumb question 😀
No problem.

As for why I'm trying to learn where the code is called, is because I usually learn a lot better when I follow the execution process.
Ultimately, all code is called from an update method. The update method of SceneManager is automatically called (by the PixiJS library) every frame. It then calls the the current scene's update method. So every frame, whatever code is within the scene's update method will be called, and then the scene will iterate through all of its children (i.e. windows, sprites, game objects) and call all of their update methods.

So basically, any update method that you see within the engine is getting automatically called every frame. Within said update methods, there will generally be code checking for various things to happen (i.e. user input, animation finished, certain property has reached a certain value, etc.) and then it will call whatever code is supposed to respond to those things.

In your particular case:
  1. SceneMap#update is called automatically each frame and proceeds to call:
  2. SceneMap#updateScene which proceeds to call:
  3. SceneMap#updateCallMenu which checks whether the menu button is pressed, and if so, it proceeds to call:
  4. SceneMap#callMenu which proceeds to initiate the menu scene
I guess the most complicated part to me stems from the size of the files. I'm used to files not being longer than 200 lines due to company policy and ease of reading.
Well the intent is not really for you to just read through 11,320 lines of rmmz_objects 😛 You have a specific thing you want to do and you find it. There are plenty of lines of code I've never seen.

(although, not knowing what you work on, 200 lines in one file seems tiny. I've written single functions with commenting that are that length...having that be a single file seems like it's taking OOP to the point of fragmentation and clutter)

Good luck with your project!

Original thread: https://forums.rpgmakerweb.com/threads/cant-find-where-menu-is-called.169311/