biud436 / MV

🏰 This plugin package includes helpful features to get you on your way to create your game in RPG Maker MV.
MIT License
64 stars 51 forks source link

How do you check if cancel button was pressed in RS_InputDialog plugin ? #40

Closed Bharat0112 closed 6 months ago

Bharat0112 commented 6 months ago

Hi, Is there any way to check if cancel button was pressed in RS_InputDialog plugin ? I am using parallel event, and needs to set self switch off if cancel button was pressed. Thank you.

biud436 commented 6 months ago

You have to insert your desired code to the function called Scene_InputDialog.prototype.cancelResult (1126 line)

https://github.com/biud436/MV/blob/96f9a3cc82ec081f15bd09b39a595032880ec060/RS_InputDialog.js#L1126-L1132

for example, you can use Event Script Calls like as below the link (E.G. common event)

https://forums.rpgmakerweb.com/index.php?threads/rpg-maker-mv-mz-script-call-list.46456/

Bharat0112 commented 6 months ago

Is there anyway to call from Game script ? Because calling self switches depend on map id as well event id. $gameSelfSwitches.setValue([1, 3, 'A'], false)

Edit : I am also using another plugin to get data from a text file, instead of retriving from pre-stored value in variable, such as password.

biud436 commented 6 months ago

Create a toggle variable, and set that toggle variable to true when the cancel button is pressed. Then, in your conditional branch, check to see if the toggle variable is 'true' and if so, make the value of that toggle variable false again.

 const TOGGLE_VAR_ID = 100;
 Scene_InputDialog.prototype.cancelResult = function () { 
   if (SceneManager._stack.length > 0) { 
    $gameVariables.setValue(TOGGLE_VAR_ID, true); // add here
     TouchInput.clear(); 
     Input.clear(); 
     this.popScene(); 
   } 
 }; 

Once you've done that, check the value for variable 100 in the conditional branch. If it's true, you've hit the cancel button. Put whatever code you want in there, and make the variable false again at the end.

Bharat0112 commented 6 months ago

I changed the code as you suggested in the plugin. Then created an event. Page 1 of the event sets Self Switch ON on Action Trigger. Now while opening InputDialog and clicking on cancel button on Page 2 of the event doesn't make Self Switch A to OFF. (Both pages have different event image so I can know.) I can see that the value of 100th variable is set to true, but still it doesn't work.

◆Plugin Command:InputDialog text Please enter the string... ◆Plugin Command:InputDialog variableID 8 ◆Plugin Command:InputDialog open ◆If:Script:$gameVariables.value(100) == "true" ◆Control Self Switch:A = OFF ◆ :End

biud436 commented 6 months ago

You don't seem to know JavaScript very well. "true" is not the same as true of boolean.

Try again with the solution below, which I've found works.

  const TOGGLE_VAR_ID = 1;
  Scene_InputDialog.prototype.cancelResult = function () {
    if (SceneManager._stack.length > 0) {
      $gameVariables.setValue(TOGGLE_VAR_ID, true);
      TouchInput.clear();
      Input.clear();
      this.popScene();
    }
  };

In my initial project, the maximum value for the variable number was 20, so 100 didn't seem to work, so I changed it to 1.

image image image

Bharat0112 commented 6 months ago

Thank you, it's working now.