MZ Make a character not move to a switch event when toggled.

Hello!
I am trying to show a window that a player can turn on/off as they please. I am using the switch "Show Window" obviously set to either ON or OFF. I use the Quick Event Creation > Switch and select the appropriate icon and when I run a test it works perfectly turning the window on and off. However... this isn't meant to be a physical switch in the map's physical location and interacted with the player's character. I think of it more as a player's HUD.

But clicking on the event obviously moves the player's character to that switch every time the player tries to turn the window on and off. Does anyone know a way that it can maintain the functionality without causing the character to move? I have tried various methods of autorun to not move the character but then switch is on a continuous loop and the switch keeps changing states. I also tried and Set Movement Route >Player empty with no movements on both event pages and the character still moves to it.

I am open to any suggestions using the method I've tried or another method.
You can disable player movement with this script
Code:
if($gamePlayer.moveByInputCached === undefined)
//This checks if the value is undefined

$gamePlayer.moveByInputCached = $gamePlayer.moveByInput;
//If it is undefined, it sets to the current value of $gamePlayer.moveByInput which is 'true'

$gamePlayer.moveByInput = function(){
return false;
}

Then enable it with this script
Code:
$gamePlayer.moveByInput = $gamePlayer.moveByInputCached;
//This resets the value of moveByInput to the cached value
I figured that it probably wasn't something coded into RPGMMZ and might need JS which is the first time I've tried something without default RPGMMZ methods or plugins. I attempted to use your JS in what I thought was the best way (posted below) but my character still moved. I set the disable movement code at the top of each event page (one page for ON and one for OFF) and then re-enable at the bottom hoping that it would stop movement when clicking on the event switch image and then allow movement as the last thing on the event page. But the character still goes to the switch.

Code:
◆Script:if($gamePlayer.moveByInputCached === undefined)
:      ://This checks if the value is undefined
:      :
:      :$gamePlayer.moveByInputCached = $gamePlayer.moveByInput;
:      ://If it is undefined, it sets to the current value of $gamePlayer.moveByInput which is 'true'
:      :
:      :$gamePlayer.moveByInput = function(){
:      :return false;
:      :}
◆Play SE:Switch1 (90, 100, 0)
◆Set Movement Route:This Event (Wait)
:                  :◇Direction Fix OFF
:                  :◇Turn Left
:                  :◇Wait:3 frames
:                  :◇Turn Right
:                  :◇Wait:3 frames
◆Control Switches:#0030 Show Quest Tracker = ON
◆Script:$gamePlayer.moveByInput = $gamePlayer.moveByInputCached;
:      ://This resets the value of moveByInput to the cached value

So I'd believe that I am misusing the code. I even tried the disable code without the re-enable code and the player character still moved. Am I just using it improperly? I do appreciate the code help as I have passing familiarity with JS (I was more CGI/PHP versed) but I haven't dug through RPGM code to know the API.
You can simplify the reference by using this script call to stop player move input:
JavaScript:
$gamePlayer.moveByInput = () => {};

To restore the code and move by input, you can delete this reference with this script call (which will not delete the original Game_Player function):
JavaScript:
delete $gamePlayer.moveByInput;

Edit: Aqua's code should work - it sounds like something is messing with the movement.

Edit edit: ninja'd haha
That script disables player movement controls. It sounds like you have some cutscene sequence that's scripting "player" movement.

You also said you're using a loop so basically you're just automatically turning movment controls off and on every x frames.
You can disable player movement with this script
Code:
if($gamePlayer.moveByInputCached === undefined)
//This checks if the value is undefined

$gamePlayer.moveByInputCached = $gamePlayer.moveByInput;
//If it is undefined, it sets to the current value of $gamePlayer.moveByInput which is 'true'

$gamePlayer.moveByInput = function(){
return false;
}

Then enable it with this script
Code:
$gamePlayer.moveByInput = $gamePlayer.moveByInputCached;
//This resets the value of moveByInput to the cached value
Note: As written, this script will work once per session and then fail forever. @bass2yang 's version corrects this flaw in addition to being simpler.

That script disables player movement controls. It sounds like you have some cutscene sequence that's scripting "player" movement

Where did you get this impression? It sounds more like they are trying to abuse terrain as UI.

I am trying to show a window that a player can turn on/off as they please. I am using the switch "Show Window" obviously set to either ON or OFF. I use the Quick Event Creation > Switch and select the appropriate icon and when I run a test it works perfectly turning the window on and off. However... this isn't meant to be a physical switch in the map's physical location and interacted with the player's character. I think of it more as a player's HUD.
Simply put: this does not work and will never work (in the base engine; plugins can do anything they want). There is no functionality to react to clicking on a specific tile on the map. Events do not react to clicks. They react to the player's presence and action. Clicking on the event doesn't activate it – it commands the player to move there, and once the player is there, the event activates because the player either stepped on the event or interacted with it.

So you're trying to work very contrary to how events are supposed to work here. I doubt there is any way to do it with pure events (even using script calls), though I would love to be proven wrong. Maybe there exists a plugin that enables events to react directly to clicks on them, but I don't know of one. I think you could get much closer to what you desire if you instead search for a HUD plugin. Another possibility to explore is a "clickable pictures" plugin. I'm aware of one or two clickable pictures plugins for MV but I don't know of any for MZ.
: As written, this script will work once per session and then fail forever.
LOL, no it doesn't. I use it in my game and disable player movement on and off at will.
I looked more closely, and you're actually correct. The code is formatted in a confusing way that makes it look like the assignment to moveByInput is inside the if == undefined, but it's actually not. Normally, you would at least indent the second line of code to make that clear, or even add braces around it.

In any case, the code doesn't really apply to the original poster's problem as I understand it…
It's not even my code. I copied and pasted it from somewhere else in the forums a while back and then just copied and pasted it from my project to this thread. You can nitpick the formatting or whatever but it works.
In any case, the code doesn't really apply to the original poster's problem as I understand it
The OP wanted to stop player pathfinding to the clicked/touched tile. That script does in fact disable input from controlling the player, including click/touch input.
Alright..so far I tried both codes but the character still moves to the event when clicking on it. I have used both the same way that I put in the code section of my second post. Since I started with a Quick Event > switch it automatically sets up two pages where the second has the condition of the switch being on and the first page has no conditions which is off since switch=off is not a usable a usable condition by default.

So I tried both codes putting the disable movement right at the top of each of the event's pages and then put the re-enable codes just above the switch assignment to either on or off. I believed that this would disable movement when the mouse i clicked on the event as the trigger for both pages is Action Button and then would re-enable movement so that the player can move their character again after they've clicked the button/switch. But I've tried that with both codes and the character still moves so I am wondering if I do not have it set up right or am using them incorrectly. The code in my previous post shows what I am doing on just one page but I am doing the same on both and the character moves to the event/button when using the switch/button for both on and off.

So far in this game I do not move character with commands at all. And on the map where I am trying to get this to work I am not moving any NPCs or the character. So there should be nothing else causing player character movement that would override a script like these. I am using only a few plugins and none of them affect or are affected by a player moving their character.

Not a loop problem as I removed the looping before I posted this. I was trying to see if using Autorun as the trigger would inhibit the character moving...which it did..but then the event just kept running and the event button just kept changing states and the window that the switch Show_Window contols kept appearing and then hiding appropriately. So it did accomplish the task of the player's character not moving to the switch when clicking it but the autorun caused a loop. So I removed that before my original post starting this thread. I only mentioned that I had tried that in case anyone were to ask me what I tried doing.

I have tried both of the JS that were offered but neither stopped the movement to the button when clicked. But I am not sure that I am putting the code where it should be. It made the most sense to put it where I did but that isn't working and if both codes work then I have to assume that I am putting them in the incorrect place. I am using Advanced (on the 3rd tab) - > Script and pasting the script. With the disable at the very top of each event page and the re-enable movement script at the bottom.
The OP wanted to stop player pathfinding to the clicked/touched tile. That script does in fact disable input from controlling the player, including click/touch input.
I don't think that's what they wanted. From my understanding, they didn't want to disable pathfinding or input. They just wanted to trigger an event remotely.

@weekendrockstar Putting the disable code in the event that you want them to click on isn't going to work. If your character is never going to move at all, you could put that code in a separate event which is set to Autorun and erases itself when done. However, if you do that, you'll no doubt find that clicking the other event ceases to function at all.

So, try setting that event to Parallel, and wrap the entire contents in a conditional with the following script condition:

Code:
TouchInput.isTriggered() && $gameMap.canvasToMapX(TouchInput.x) == this.x && $gameMap.canvasToMapY(TouchInput.y) == this.y
Alright..so far I tried both codes but the character still moves to the event when clicking on it. I have used both the same way that I put in the code section of my second post. Since I started with a Quick Event > switch it automatically sets up two pages where the second has the condition of the switch being on and the first page has no conditions which is off since switch=off is not a usable a usable condition by default.

So I tried both codes putting the disable movement right at the top of each of the event's pages and then put the re-enable codes just above the switch assignment to either on or off. I believed that this would disable movement when the mouse i clicked on the event as the trigger for both pages is Action Button and then would re-enable movement so that the player can move their character again after they've clicked the button/switch. But I've tried that with both codes and the character still moves so I am wondering if I do not have it set up right or am using them incorrectly. The code in my previous post shows what I am doing on just one page but I am doing the same on both and the character moves to the event/button when using the switch/button for both on and off.

So far in this game I do not move character with commands at all. And on the map where I am trying to get this to work I am not moving any NPCs or the character. So there should be nothing else causing player character movement that would override a script like these. I am using only a few plugins and none of them affect or are affected by a player moving their character.

Not a loop problem as I removed the looping before I posted this. I was trying to see if using Autorun as the trigger would inhibit the character moving...which it did..but then the event just kept running and the event button just kept changing states and the window that the switch Show_Window contols kept appearing and then hiding appropriately. So it did accomplish the task of the player's character not moving to the switch when clicking it but the autorun caused a loop. So I removed that before my original post starting this thread. I only mentioned that I had tried that in case anyone were to ask me what I tried doing.

I have tried both of the JS that were offered but neither stopped the movement to the button when clicked. But I am not sure that I am putting the code where it should be. It made the most sense to put it where I did but that isn't working and if both codes work then I have to assume that I am putting them in the incorrect place. I am using Advanced (on the 3rd tab) - > Script and pasting the script. With the disable at the very top of each event page and the re-enable movement script at the bottom.
My apologies - I thought the code would be enough so now I'm going to try to focus on the simple matter at hand - completely stopping player movement by touch or key input:

To disable the clicking and player input during the Scene_Map (your main scene during gameplay), you can try this:
JavaScript:
SceneManager._scene.processMapTouch = () => {};
$gamePlayer.moveByInput = () = {};
To return everything to normal:
JavaScript:
delete SceneManager._scene.processMapTouch;
delete $gamePlayer.moveByInput;

Edit: If the SceneManager code does more than you need on the map, you can focus on just the setDestination part by using this instead of it:
JavaScript:
$gameTemp.setDestination = () => {};
and:
JavaScript:
delete $gameTemp.setDestination;
So, it sounds like the issue is that you have a UI element that you need to turn on when it's clicked, but you don't want the player to move to it when it's clicked (which is what happens when you make the element an event on the map).

Would the ButtonPicture.js plugin (one of the default plugins) solve the issue? It triggers a common event when a picture is clicked. While I haven't had to use it for a project yet, it would be my first try for any sort of clickable UI.
I appreciate your response and I did run into ButtonPicture.js once I paid attention to the plugins that were in there by default. I did work with it very briefly but I ran into that while I was working on another feature in the game so I did not give it serious look into yet. If I figure out how to properly employ it then it should do what I need. I was only going with a physical graphical switch as I felt that it would also work for the UI graphic element. I am going to try this plugin once I return my attention to that feature.

Original thread: https://forums.rpgmakerweb.com/threads/make-a-character-not-move-to-a-switch-event-when-toggled.178101/