I want to add a popup window to a scene where after choosing an option, it shows a popup that says "Are you sure?" with the options "Yes" and "No" where if you choose "Yes" it runs a command. Is there a simple way to do this, because everything I've seen so far looking into it make it seem like a complex and coding-heavy task for something so basic.
MZ Simple "Are you sure?" Popup
Javascript/Plugin SupportPresuming you mean scene in the technical sense of MZ's scenes, no, there's not a very easy way to do it. Modifying the UI is one of the more complicated aspects of the codebase.
If you mean scene like something that happens in your game, that would be a simple Show Choices event command.
If you mean scene like something that happens in your game, that would be a simple Show Choices event command.
I meant like having it happen in a scene. Maybe not as a popup that appears over other menu windows, but a separate option window.
I tried making a separate scene with just a yes/no option choice, but I kept getting an "argument must be rectangle" error.
I tried making a separate scene with just a yes/no option choice, but I kept getting an "argument must be rectangle" error.
You'll need a custom Window class for your choices and custom logic for the related Scene(s) to determine when to display and activate the choice window and what to do based on the inputs.
You assert that it's something "so basic," but, frankly, you didn't even provide a basic explanation of what it is that you want to do. "Running a command" on a yes input could mean quite literally anything and could very well be even more complex than implementing the choice window and related logic.
The alternative might be a plugin that lets you run common events within the menu scene, but whether or not that approach would be viable would depend on, again, what you actually want to do.
You assert that it's something "so basic," but, frankly, you didn't even provide a basic explanation of what it is that you want to do. "Running a command" on a yes input could mean quite literally anything and could very well be even more complex than implementing the choice window and related logic.
The alternative might be a plugin that lets you run common events within the menu scene, but whether or not that approach would be viable would depend on, again, what you actually want to do.
It's impossible to say concretely what you did wrong when you don't show the code you used or the actual error message (when you get errors, press F8, go to the Console tab, and provide a screenshot of the full trace) - but it doesn't sound like you did it in the correct way.
Scenes don't have choices - scenes are just the organizational container for windows. And I don't know why you'd want to try to make it a separate scene from the scene you're choosing the option in - you need to affect things in that scene, not go to a different one.
But it's like @Kenen said - you need to code the new window (not necessarily with a custom class, I don't see why a regular Window_Selectable wouldn't work for a yes/no choice), add the command handlers to that window and to the scene.
You may find someone willing to do it for you without having to commission the work, but you'll need to be much more specific about where you're doing this and what you want it to do, on which command, etc. It's not generic or plug 'n' play code.
Never assume something is simple just because the player's options are limited (yes and no). Lets break it down:
- You need to add 2 Windows (Text and Yes/No) to the scene
- You need to define the windows x, y, width, and height
- You need to define that the window shows "Are you sure?"
- You likely want to define that the text is centered
- You need to define when the windows are visible
- You need to deviate the original command to open your new window
- You need to define that, while the dialog is open, all other windows are deactivated
- You need to define what happens when the player confirms
- ... and cancels
When you struggle with "argument must be a rectangle" then I guess..
Welcome in the world of programming! Everyone starts at zero, but this task is too huge for you. However, you can tell us which scene you are referring to and maybe you find someone who will do that for you. Again, please don't this is a simple task, even for me it would take roughly half an hour.
- You need to add 2 Windows (Text and Yes/No) to the scene
- You need to define the windows x, y, width, and height
- You need to define that the window shows "Are you sure?"
- You likely want to define that the text is centered
- You need to define when the windows are visible
- You need to deviate the original command to open your new window
- You need to define that, while the dialog is open, all other windows are deactivated
- You need to define what happens when the player confirms
- ... and cancels
When you struggle with "argument must be a rectangle" then I guess..
Welcome in the world of programming! Everyone starts at zero, but this task is too huge for you. However, you can tell us which scene you are referring to and maybe you find someone who will do that for you. Again, please don't this is a simple task, even for me it would take roughly half an hour.
Good news, I figured out how to do the choice box!
Bad news, I don't know how to add the plain "Are you sure" text box.
Bad news, I don't know how to add the plain "Are you sure" text box.
When you upload what you already have, we may can help you.
Probably, you can add the text window the same as you add the dialog window; just let this text window derive from Window_Base instead of Window_Command.
Probably, you can add the text window the same as you add the dialog window; just let this text window derive from Window_Base instead of Window_Command.
Tried that, couldn't figure out how to make it work. Could anyone give me a super-basic explanation for adding a text box? Don't be afraid to spell it out to me, so far I've kind of been taking the "learning how to fly by jumping off a cliff" approach to scripting.
Here's my code for the decisions scene if that helps. Don't be fooled by how not-completely-terrible it looks, I mainly made this by using the options menu code as a template. Tried a similar approach to a text box with the "Help" window code, but I couldn't get that to work for me.
Here's my code for the decisions scene if that helps. Don't be fooled by how not-completely-terrible it looks, I mainly made this by using the options menu code as a template. Tried a similar approach to a text box with the "Help" window code, but I couldn't get that to work for me.
//-----------------------------------------------------------------------------// Window_SuperBasicDecision//function Window_SuperBasicDecision() { this.initialize(...arguments);}Window_SuperBasicDecision.prototype = Object.create(Window_Command.prototype);Window_SuperBasicDecision.prototype.constructor = Window_SuperBasicDecision;Window_SuperBasicDecision.prototype.initialize = function(rect) { Window_Command.prototype.initialize.call(this, rect);};Window_SuperBasicDecision.prototype.makeCommandList = function() { this.addChoices();};Window_SuperBasicDecision.prototype.addChoices = function() { this.addCommand("Yes", "yes"); this.addCommand("No", "cancel");};Window_SuperBasicDecision.prototype.drawItem = function(index) { const title = this.commandName(index); const rect = this.itemLineRect(index); const titleWidth = rect.width; this.resetTextColor(); this.changePaintOpacity(this.isCommandEnabled(index)); this.drawText(title, rect.x, rect.y, titleWidth, "center");};//-----------------------------------------------------------------------------// Scene_SuperBasicDecision//function Scene_SuperBasicDecision() { this.initialize(...arguments);}Scene_SuperBasicDecision.prototype = Object.create(Scene_MenuBase.prototype);Scene_SuperBasicDecision.prototype.constructor = Scene_SuperBasicDecision;Scene_SuperBasicDecision.prototype.initialize = function() { Scene_MenuBase.prototype.initialize.call(this);};Scene_SuperBasicDecision.prototype.create = function() { Scene_MenuBase.prototype.create.call(this); this.createSuperBasicDecisionWindow();};Scene_SuperBasicDecision.prototype.terminate = function() { Scene_MenuBase.prototype.terminate.call(this);};Scene_SuperBasicDecision.prototype.superBasicDecisionWindowRect = function() { const ww = 200; const wh = this.calcWindowHeight(1, true); const wx = (Graphics.boxWidth - ww) / 2; const wy = (Graphics.boxHeight - wh) / 2; return new Rectangle(wx, wy, ww, wh);};Scene_SuperBasicDecision.prototype.createSuperBasicDecisionWindow = function() { const rect = this.superBasicDecisionWindowRect(); this._superBasicDecisionWindow = new Window_SuperBasicDecision(rect); this._superBasicDecisionWindow.setHandler("yes", this.commandYes.bind(this)); this._superBasicDecisionWindow.setHandler("cancel", this.popScene.bind(this)); this.addWindow(this._superBasicDecisionWindow);};Scene_SuperBasicDecision.prototype.superBasicDecisionWindowRect = function() { const n = this.numberOfCommands(); const ww = 200; const wh = this.calcWindowHeight(n, true); const wx = (Graphics.boxWidth - ww) / 2; const wy = (Graphics.boxHeight - wh) / 2; return new Rectangle(wx, wy, ww, wh);};Scene_SuperBasicDecision.prototype.numberOfCommands = function() { // Increase this value when adding option items. return 2;};Scene_SuperBasicDecision.prototype.commandYes = function() { // Insert Command Here};
JavaScript:
Scene_SuperBasicDecision.prototype.create = function() {
Scene_MenuBase.prototype.create.call(this);
this.createSuperBasicDecisionWindow();
};
Here, you have already created the command window. Adding a text window is the same thing, just a different window. The Help Window class could become handy for you because it has a "setText" method.
JavaScript:
Scene_SuperBasicDecision.prototype.create = function() {
Scene_MenuBase.prototype.create.call(this);
this.createSuperBasicDecisionWindow();
const rectangle = new Rectangle(x, y, width, height); // FILL THIS INFO AS YOU NEED
this._helpWindow = new Window_Help(rectangle);
this._helpWindow.setText("Are you sure?");
this.addWindow(this._helpWindow);
};
That's helpful, but how can I reference the dimensions of the choice box to ensure that the text box is always directly on top of it? Having to figure out the exact y-coordinate manually isn't very fun.
aside from the above, you also have an error:
this is called twice: superBasicDecisionWindowRect
why though? you probably should rename 1 as it conflict with each other
or rewrite the other (which is lower I think).
this is called twice: superBasicDecisionWindowRect
why though? you probably should rename 1 as it conflict with each other
or rewrite the other (which is lower I think).
You can reference the window with
This is just a brief example.
this._superBasicDecisionWindow, but sometimes it's much cooler to call the rectangle function a 2nd time 😉
Code:
const commandWindowRectangle = this.superBasicDecisionWindowRect();
const rectangle = new Rectangle(
commandWindowRectangle.x,
commandWindowRectangle.y + commandWindowRectangle.height,
commandWindowRectangle.width,
this.calcWindowHeight(1),
);
this._helpWindow = new Window_Help(rectangle);
...
Original thread: https://forums.rpgmakerweb.com/threads/simple-are-you-sure-popup.173818/