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,021
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,639
Reaction score
3,770
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,021
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,639
Reaction score
3,770
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,021
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
162
Reaction score
154
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 Profile Posts

imgur sure is getting weird, one day I lose gradually all my images, the other I get them back randomly and then again they disappear again.
Despite OPT2 praise it still has some strange stories in it. Lady Mikka is trying to work herself to death because of guilt. Guilt over what? ¯\_(ツ)_/¯ So instead of finding a NPC to have a heart to heart with her they decide the cure is a new kimono. So when she drops dead she'll at least be well dressed. I haven't even got to the strange part yet.
Did so much work on the game today. I wish I could post it all in this status update but there is a character limit of course haha. I thought about making a topic for updates, though... maybe.
The most recent sign that I am old. I have done martial arts for over 4 decades. Never HAD to stretch out. Good, of course, but never required. Was doing some kicks in the kitchen because, why not, and I felt a pop in the back of my thigh. Now I am limping around. Gotta love getting old.
One of the biggest perks of being fluent in English is how many new and interesting recipes I am able to find and try out that I would have hardly come across if I just spoke my mothertounge :3

Forum statistics

Threads
131,682
Messages
1,222,221
Members
173,435
Latest member
TheAmplifier
Top