MZ Need help with understanding how methods are initialized in JavaScript for MZ

Hi I am someone who is very new to coding (literally zero experience in coding) and recently I am trying to pick up script writing and plugin creation in RPG maker.

Currently I am running into a problem with trying to get Js to create multiple instances of the Equip Window in the Equip Scene in game (I'm trying to make a loadout system that allows players to equip different sets of equipment loadouts and change them mid combat), the problem I'm having now is that I am able to create 3 different Equip Windows for the Equip Scene but the Equip Slots are not showing up except for the first window, so what it looks like now is my first window looks normal with all the Equip Slots present but my second and third windows are just empty windows without the Equip Slots in the middle.

To help make my problem clearer below is the code I'm trying to edit (I apologize if my code looks dumb or redundant, right now I'm just trying to achieve my desired outcome lol),

1738130642600.png


So here I tried to overwrite the Scene_Equip.prototype.createSlotWindow function to make three separate Equip Windows hence the _slotWindows, _slotWindows2 and _slotWindows3. But the game only initialized the Window_EquipSlot(rect) method for the first _slotWindows. I looked through some post on the forum and some of them mentioned something about Js only initializing the method once for the first instance and not doing it for subsequence ones.

Would really appreciate any guidance/pointers as to how the Window_EquipSlot(rect) method is being initialized (do I need to edit some code for the method as well) or if the way I'm doing this is even correct to begin with (maybe the way I added the extra windows was incorrect) so I can troubleshoot this problem. Thanks a lot!

ps. In terms of my coding abilities I'm still learning the some fundamentals through online courses and I figured the best way for me to learn is to learn the basics while doing some actual coding as well.
Hi I am someone who is very new to coding (literally zero experience in coding) and recently I am trying to pick up script writing and plugin creation in RPG maker.
my first recommendation then is to do guided tutorials until you have a good enough understanding of JS to be able to read and understand the code within the js folder before jumping into scene and window management. those are the most complex parts of the engine imo and arent beginner friendly for a few reasons.

But the game only initialized the Window_EquipSlot(rect) method for the first _slotWindows. I looked through some post on the forum and some of them mentioned something about Js only initializing the method once for the first instance and not doing it for subsequence ones.
a method isnt initialized. initialization is just assigning an initial value to something. in the code youve written you have created the other 2 windows. you hid them after creation, but theyre there. if you open up the devtools console while in the equip menu, you can access them with SceneManager._scene._slotWindow2 and _slotWindow3.

the issue as far as i can see is that those are the only changes youve made.

they all use the same rect function and are all going to be placed on top of each other, but maybe thats intended.

Then, those other windows arent going to have anything in them if you were to show them. there are functions within the scene that manipulate what its _slotWindow contains. adding new windows wont magically tell the scene what to do with them, so anywhere that does anything to the ._slotWindow needs to be updated to also do stuff to the other 2 or you need to make new functions specific for the other 2 windows and call them when needed.

Then they all share the same handlers and are all functionally the same except said handlers would only do anything to the _slotWindow. the ok handler there hides the _slotWindow to show the _itemWindow. Even if you were to do stuff on _slotWindow3, only the _slotWindow gets hidden.
I looked through some post on the forum and some of them mentioned something about Js only initializing the method once for the first instance and not doing it for subsequence ones.
Like Robro said, wherever you found that info, it certainly doesn't apply here. 😅

In this case I think it would be much simpler to not make any changes to the display objects. Equipment stats, traits, etc are checked in various places. If you want to swap out the equipment, then just do that: it should automatically work with everything. E.g.
  1. The original "equip set" can be "set 0" (default).
  2. Define a new actor property where alternative equip sets are stored (1, 2, etc).
  3. Define a new actor property that indicates which equip set is currently in use (0, 1, 2, etc).
  4. Patch the equips method of Game_Actor based on steps 2 & 3.
    [Edit: on second thought, you'd probably have to swap out the _equips property instead.]
  5. To change equip set, change the value of the property from step 3 and refresh the slot window.
Note that even with these steps, this will probably be quite challenging to get right if you have little experience in (object-oriented) programming, let alone working with an existing codebase.

Also, since this is more of a "learning" topic~

I've moved this thread to Learning JavaScript (from JavaScript Support). Thank you.

my first recommendation then is to do guided tutorials until you have a good enough understanding of JS to be able to read and understand the code within the js folder before jumping into scene and window management. those are the most complex parts of the engine imo and arent beginner friendly for a few reasons.


a method isnt initialized. initialization is just assigning an initial value to something. in the code youve written you have created the other 2 windows. you hid them after creation, but theyre there. if you open up the devtools console while in the equip menu, you can access them with SceneManager._scene._slotWindow2 and _slotWindow3.

the issue as far as i can see is that those are the only changes youve made.

they all use the same rect function and are all going to be placed on top of each other, but maybe thats intended.

Then, those other windows arent going to have anything in them if you were to show them. there are functions within the scene that manipulate what its _slotWindow contains. adding new windows wont magically tell the scene what to do with them, so anywhere that does anything to the ._slotWindow needs to be updated to also do stuff to the other 2 or you need to make new functions specific for the other 2 windows and call them when needed.

Then they all share the same handlers and are all functionally the same except said handlers would only do anything to the _slotWindow. the ok handler there hides the _slotWindow to show the _itemWindow. Even if you were to do stuff on _slotWindow3, only the _slotWindow gets hidden.
Alright thank you for the pointers, you're right in that I still need to master my fundamentals so I can fully understand the codes, but I still plan on working on this script whenever I can as some form of practical learning, but still thank you very much for the guidance I'll be sure to check for the other functions in the scene and see if I can figure something out from there.
But the game only initialized the Window_EquipSlot(rect)
how can you tell?
if the game didn't crash when you sent an instruction to window2, it means window2 is there.
Like Robro said, wherever you found that info, it certainly doesn't apply here. 😅

In this case I think it would be much simpler to not make any changes to the display objects. Equipment stats, traits, etc are checked in various places. If you want to swap out the equipment, then just do that: it should automatically work with everything. E.g.
  1. The original "equip set" can be "set 0" (default).
  2. Define a new actor property where alternative equip sets are stored (1, 2, etc).
  3. Define a new actor property that indicates which equip set is currently in use (0, 1, 2, etc).
  4. Patch the equips method of Game_Actor based on steps 2 & 3.
  5. To change equip set, change the value of the property from step 3 and refresh the slot window.
Note that even with these steps, this will probably be quite challenging to get right if you have little experience in (object-oriented) programming, let alone working with an existing codebase.

Also, since this is more of a "learning" topic~
Moved to: Learning JavaScript (from JavaScript Support)
Thanks for the tip, I'll be honest it's taking me quite a lot of effort to full grasp the steps you showed me ( because yeah I'm not very knowledgeable in object-oriented programming XD, something I'm currently still learning), but I appreciate it still as it gives me some directions to work towards, thank you.
how can you tell?
if the game didn't crash when you sent an instruction to window2, it means window2 is there.
Yeah I know the second window is there because when I run my own function to show window2 it pops up an empty window that doesn't have the equip slot inside, but when I switch to the first window again it is able to show the normal equip window with the equip slots inside, so I assumed what happend was the function for creating a second and third window worked but not for
creating the their respective equip slots.
an empty window that doesn't have the equip slot inside
is *the scene's refresh method* correctly redirected to *the active window* in question?

the scene automatically refreshes it's own default window: the original one.
if you create new ones, you have to rewire the whole scene, not just the creation method.
is *the scene's refresh method* correctly redirected to *the active window* in question?

the scene automatically refreshes it's own default window: the original one.
if you create new ones, you have to rewire the whole scene, not just the creation method.
Ahh...most likely not since I didn't even considered that the refresh method could be incorrect, I'll be looking back at the code to check for the refresh method, thanks for the help.
the scene automatically refreshes it's own default window
I'll be looking back at the code to check for the refresh method
Just to clarify, the equip scene doesnt use an update loop or a refresh method to automatically update the windows when theyre active. those windows are only refreshed on creation and as a part of the handler functions.

as far as just displaying stuff on the windows goes, your big issue is that you never set an actor to those windows. as mentioned before, the scene already takes care of the _slotWindow, but you still need do stuff with the others. just refreshing them wont do anything as the window's drawItem function doesnt display anything without an actor set

the scene's refreshActor method sets an actor to all the relevant windows using their own setActor methods, and the windows call their refresh method at the end of their setActor function. you want to add the command to set your new windows' actors to the scene's refreshActors method.

Thats a part of why i usually encourage beginners to do more learning about JS before touching windows and scenes. to understand the full picture you often have to cross reference functions within multiple files

Original thread: https://forums.rpgmakerweb.com/threads/need-help-with-understanding-how-methods-are-initialized-in-javascript-for-mz.175026/