alreadytaken12

Villager
Member
Joined
Dec 12, 2022
Messages
17
Reaction score
2
First Language
portuguese
Primarily Uses
RMMV
I make a little script to add a new menu command.
This command turn on the 10th switch. But the games frezzes after being selected
Anyway to prevent the code to frezzes the game?
1680197508047.png
1680197555569.png
JavaScript:
(function() {
   Window_MenuCommand.prototype.addOriginalCommands = function() {
       this.addCommand("Teste", "comando");
   };

   Scene_Menu.prototype.createCommandWindow = function() {
       this._commandWindow = new Window_MenuCommand(0, 0);
       this._commandWindow.setHandler('comando', this.commandcomando.bind(this));
       this.addWindow(this._commandWindow);
   };

   Scene_Menu.prototype.commandcomando = function() {
       $gameSwitches.setValue(10, true);
   };
})();
 

ShadowDragon

Realist
Veteran
Joined
Oct 8, 2018
Messages
7,513
Reaction score
3,022
First Language
Dutch
Primarily Uses
RMMV
there are serveral, as "addOriginalCommands" should be aliased,
instead of overwriting, secondly, the commandcando keeps ON,
as it doesn't trigger anything or turn it off.

if that switch is bound to a common event, you can better use
$gameTemp.reserveCommonEvent(ID)
ID being the common event ID you use.

where you call that to toggle it on and off, depending what it does.

while there is very low information what this command should do,
we cannot really help you to correct what needs to be done correctly.
 

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
4,646
Reaction score
3,777
First Language
EN
Primarily Uses
RMMZ
Add this._commandWindow.activate() to your commandcomando method.

(By default Window_Selectable deactivates itself when it processes the OK input.)
 

alreadytaken12

Villager
Member
Joined
Dec 12, 2022
Messages
17
Reaction score
2
First Language
portuguese
Primarily Uses
RMMV
there are serveral, as "addOriginalCommands" should be aliased,
instead of overwriting, secondly, the commandcando keeps ON,
as it doesn't trigger anything or turn it off.

if that switch is bound to a common event, you can better use
$gameTemp.reserveCommonEvent(ID)
ID being the common event ID you use.

where you call that to toggle it on and off, depending what it does.

while there is very low information what this command should do,
we cannot really help you to correct what needs to be done correctly.
The command should turn on the 10th switch when is turned off, and vice versa
 

alreadytaken12

Villager
Member
Joined
Dec 12, 2022
Messages
17
Reaction score
2
First Language
portuguese
Primarily Uses
RMMV
Add this._commandWindow.activate() to your commandcomando method.

(By default Window_Selectable deactivates itself when it processes the OK input.)
Where part of the code i should I put it exactly? Im Kinda confused
 

ShadowDragon

Realist
Veteran
Joined
Oct 8, 2018
Messages
7,513
Reaction score
3,022
First Language
Dutch
Primarily Uses
RMMV
JavaScript:
Scene_Menu.prototype.commandcomando = function() {
    if ($gameSwitches.value == false) {
        $gameSwitches.setValue(10, true);
        this._commandWindow.activate()
    } else {
        $gameSwitches.setValue(10, false)
        this._commandWindow.deactivate()
    }
};
this might work, but there might be a cleaner way to do it though
 

alreadytaken12

Villager
Member
Joined
Dec 12, 2022
Messages
17
Reaction score
2
First Language
portuguese
Primarily Uses
RMMV
JavaScript:
Scene_Menu.prototype.commandcomando = function() {
    if ($gameSwitches.value == false) {
        $gameSwitches.setValue(10, true);
        this._commandWindow.activate()
    } else {
        $gameSwitches.setValue(10, false)
        this._commandWindow.deactivate()
    }
};
this might work, but there might be a cleaner way to do it though
The command works, but the screen still frezzing after selecting the command (making it stuck at the game menu).
 

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
4,646
Reaction score
3,777
First Language
EN
Primarily Uses
RMMZ
I meant like this:
JavaScript:
   Scene_Menu.prototype.commandcomando = function() {
       $gameSwitches.setValue(10, true);
       this._commandWindow.activate();
   };
If you want the command to toggle switch 10 on/off instead of just turning it on, try this instead:
JavaScript:
   Scene_Menu.prototype.commandcomando = function() {
       $gameSwitches.setValue(10, !$gameSwitches.value(10));
       this._commandWindow.activate();
   };
 

ShadowDragon

Realist
Veteran
Joined
Oct 8, 2018
Messages
7,513
Reaction score
3,022
First Language
Dutch
Primarily Uses
RMMV
its cleaner, but I also think calling a common event is better as you
can control the switch there to toggle switch ON/OFF whatever
should happen.

so in the common event, you can do something like:

if: switch 10 = OFF
switch 10 = ON
else
switch 10 = OFF
end

but whatever happend can be set below the commond, but if you just need
to turn it on for the ingame mechanic, you can do caethyril solution which will
work, but it will be hard to pinpoint why freezes.

you could also hard code in the command list where you have the
other commands that you simply overwrite to add the command
whereever you want between item and game end without using the
addOriginalCommands.

another way is to use a menu customiser, like YEP_MainMenuManager
or CGMV_MenuCommands, so you can eval the commands for the
switch for an easy to toggle switch there.

but the possibility are endless, depending what the switch does or what
it is calling.
 

Mac15001900

Veteran
Veteran
Joined
Aug 7, 2022
Messages
163
Reaction score
155
First Language
English
Primarily Uses
RMMV
You should probably alias Scene_Menu.prototype.createCommandWindow instead of overwriting it: currently you've removed the functionality of all the other buttons. You might want to do something like this:

JavaScript:
let _Scene_Menu_createCommandWindow = Scene_Menu.prototype.createCommandWindow;
Scene_Menu.prototype.createCommandWindow = function() {
    _Scene_Menu_createCommandWindow.call(this);
    this._commandWindow.setHandler('comando', this.commandcomando.bind(this));
};

Also try to disable your other plugins and see if that affects anything - if one of them is also modifying these functions it could cause problems.
 
Last edited:

alreadytaken12

Villager
Member
Joined
Dec 12, 2022
Messages
17
Reaction score
2
First Language
portuguese
Primarily Uses
RMMV
Solved the screen frezzing problem, the "SceneManager.push(Scene_Menu);" at the end of the script, thank for everyone for help me in this thread.
 

Latest Threads

Latest Posts

Latest Profile Posts

Hamburger!? Yeeah.
I love it when the approval queue is 80% spammers. Makes it so fast to power through!
I found some inspiration and have started work on a Point and Click style exploration game in a dead mall. I am hopefully going to push MZ in some unexpected directions. I always love seeing the engine do things that folks might not expect. Its good to have found some direction. Thanks for the support a few weeks back when the writers blog was hitting heavy.
Don't you want your heroes or monsters to lose some of their MAXHP or MAXMP? Don't you?
Really, why wouldn't you? :p
Yeah, it's gonna get worse after every hit they take, but so what?
Aren't they courageous fighters? Or stupidly brute mobsters?

Forum statistics

Threads
131,730
Messages
1,222,708
Members
173,476
Latest member
quicksandJo
Top