MV Undo Last Movement/Action

Undo Last Movement/Action Plugin Request [RPG Maker MV]

Introduction
A staple of block-pushing puzzle games like Sokoban is the ability to undo a move/action by hitting a key. RPG Maker MV has reset functionality in the form of transferring the player out of the map and back to the map, essentially resetting the puzzle, bur we don't have single action undo options yet. Using existing Plugins I've been able to key a full reset to the R key on the keyboard, but have had no such luck for undos.

While I've looked into the components of such a system for other engines (I hear a lot about undo stacks, command patterns, move tables, etc.) they fall outside of my level of coding comfort.

Request
Ideally, the plugin would have the following features:
  • Link the undo action to a configurable keyboard command.
  • Track actions taken, including movement (player and event), interacting with an object, switches, variables, etc. Hitting the undo key should revert all changes applied by the previous action.
  • Clear action log/begin tracking action log with a script or event call.
    • I imagine the main use will be clearing and restarting on map transitions, but this could also be useful for checkpoints or level/stage completion.
  • Have a configurable maximum undo length with the option for no undo limits within the same map.
Using an example from the upcoming Isles of Sea and Sky, you can see the main character moving a box object.

1713989973824.png
Hitting the undo key would bring that box right back to the position it was pushed from.

1713990068777.png

​
The same would be true for character movement, switches/variables changing, etc.

Thank you very much for any help you can provide towards implementing this mechanic. I'm sure a lot of puzzle making enthusiasts would appreciate this option.
​
You could do this without a plugin by just storing the event's id and x and y position in an array before you move it. Then the "undo command" would just get that event id and set its position to the array positions.
You could implement this with a parallel event on each map. You'd have four variables for each event to store their old and current X/Y coordinates.

Every few frames, you check whether each event's coordinates match their current (in variables) coordinates. If no, you save the current variables into the old variables and the actual coordinates into the current variables.

No need to even get into script calls with arrays.
You could do this without a plugin by just storing the event's id and x and y position in an array before you move it. Then the "undo command" would just get that event id and set its position to the array positions.
How would you do this after every player movement though?
You could implement this with a parallel event on each map. You'd have four variables for each event to store their old and current X/Y coordinates.

Every few frames, you check whether each event's coordinates match their current (in variables) coordinates. If no, you save the current variables into the old variables and the actual coordinates into the current variables.

No need to even get into script calls with arrays.
I considered that but then how would you undo more than once? Wouldn't you always be stuck at just undoing the last action only?
How would you do this after every player movement though?
Ok, yeah, this part may need a plugin to alias the isMoveSuccessful() function, or just be constantly storing and comparing coordinates in a parallel event like ATT_Turan recommended.

how would you undo more than once? Wouldn't you always be stuck at just undoing the last action only?
You'd have to push every previous player position and event position in an array every time it changed. Then iterate one position in the array for every step backward.
Ok, yeah, this part may need a plugin to alias the isMoveSuccessful() function, or just be constantly storing and comparing coordinates in a parallel event like ATT_Turan recommended.


You'd have to push every previous player position and event position in an array every time it changed. Then iterate one position in the array for every step backward.
Noted! Still a bit outside my wheelhouse but if someone picks up the request it's something I can point them to. Will keep an eye out and worse case I try throwing this to commissioned plugin requests down the line if it doesn't get picked up.

Thanks for the support!
I considered that but then how would you undo more than once? Wouldn't you always be stuck at just undoing the last action only?
Yeah, if you wanted it infinitely expandable to the beginning of the level, then you'd probably need to get into coding territory with pushing stuff into arrays like AquaEcho said.

worse worst case I try throwing this to commissioned plugin requests down the line if it doesn't get picked up.
That's pretty likely - people tend to grab free plugin requests if they're simple to do or useful for many people, and this is neither. It's both moderately complex and pretty niche for your game.
I want to say that I maybe saw a Japanese plugin for this, but you'd have to look through Fungamemake for it.
I want to say that I maybe saw a Japanese plugin for this, but you'd have to look through Fungamemake for it.
Thanks for the tip; will do a search for it!
I could probably write this plugin since I already have a plugin that logs player path so it would just be modifying it. I'd just have to put my ChronoEngine guide on hold to do it.

I'll take a stab at this next week but I want to finish my Chrono Engine guides first.
I could probably write this plugin since I already have a plugin that logs player path so it would just be modifying it. I'd just have to put my ChronoEngine guide on hold to do it.

I'll take a stab at this next week but I want to finish my Chrono Engine guides first.
Definitely won't turn away the help! Appreciate it a lot! I can chug along without the plugin for a good while more so don't feel like you need to rush anything.

Big thanks!
You can try this out. It won't undo switches or self switches- I'm not sure what the best way to handle that would be without making the player do a lot of work on their end. Also if you have spawned events it'll bug out. Fixed the spawned event issue

If you want to trigger it with a button press you'll need to use it with another plugin like Hakuen Studio Button Common Events because I didn't program that in yet
You can try this out. It won't undo switches or self switches- I'm not sure what the best way to handle that would be without making the player do a lot of work on their end. Also if you have spawned events it'll bug out. Fixed the spawned event issue

If you want to trigger it with a button press you'll need to use it with another plugin like Hakuen Studio Button Common Events because I didn't program that in yet
Wow, thank you! Will give it a shot as soon as possible. I have a button press plugin so I should be good to go. I think I can manage the switches by having the game run checks to see if blocks are on specific X/Ys after moving blocks but also after hitting the rewind CE. Keep you posted!

You can try this out. It won't undo switches or self switches- I'm not sure what the best way to handle that would be without making the player do a lot of work on their end. Also if you have spawned events it'll bug out. Fixed the spawned event issue

If you want to trigger it with a button press you'll need to use it with another plugin like Hakuen Studio Button Common Events because I didn't program that in yet
Loaded into a blank project and while the plugin can indeed rewind movements (yay!) it doesn't memorize direction facing (not a huge issue) but more importantly the character no longer has any collision. Even with eventing I wasn't able to restore collision properties. I could walk through any terrain and through all events, even those set as "Same character" level.

Will keep testing!
Loaded into a blank project and while the plugin can indeed rewind movements (yay!) it doesn't memorize direction facing (not a huge issue)
This wouldn't be hard to add
but more importantly the character no longer has any collision. Even with eventing I wasn't able to restore collision properties. I could walk through any terrain and through all events, even those set as "Same character" level.
All right, I'll see if I can figure out what's causing this

Edit: This should fix both of those issues. I'll see about adding undoing of switches and variables which will be a bit more work.
This wouldn't be hard to add

All right, I'll see if I can figure out what's causing this

Edit: This should fix both of those issues. I'll see about adding undoing of switches and variables which will be a bit more work.
You're a champ. Will give this a look as soon as I can after date night.
another step back or more (this could have bugs and not fully tested
as it was made for his gameJam) is Gimmer_BeKindRewind and require
it's core.

I think it could revert switches/variables too, but unsure.
but if it's need to be plain simple for steps only, I think Aqua's plugin
is more than enough.
another step back or more (this could have bugs and not fully tested
as it was made for his gameJam) is Gimmer_BeKindRewind and require
it's core.

I think it could revert switches/variables too, but unsure.
but if it's need to be plain simple for steps only, I think Aqua's plugin
is more than enough.
Haha, If I knew this existed I wouldn't have written mine. Oh well, mine does work with diagonal movement and works stand alone. I also half finished the switches and variables so might as well finish it.
Gimmer one can be buggy, it's better for stable than bugged version.
as it works simple moves, but not extensive tested with everything else.
so it can crash or bug more 😀

Stand alone is can be useful, but it cores is to read some data, specially
for plugin commands to make it easier.

Original thread: https://forums.rpgmakerweb.com/threads/undo-last-movement-action.168051/