How to get undo to work?

Place to post guides, observations, things related to modding that are not mods themselves.
ndh
Inserter
Inserter
Posts: 23
Joined: Sat Apr 29, 2023 7:19 pm
Contact:

How to get undo to work?

Post by ndh »

I made a mod that adds and removes red and green wires. How do I add undo support?

I found LuaUndoRedoStack, but I don't see a way to add anything to the stack. Is this possible?

The mod defines a selection-tool, similar to https://mods.factorio.com/mod/WideChests. on_event(defines.events.on_player_selected_area, it calls LuaWireConnector.connect_to.

Any way to make it work?

Edit: Found this topic: viewtopic.php?p=558266. Doesn't seem possible in general. Still wondering if there's some way to make it work.
sparr
Smart Inserter
Smart Inserter
Posts: 1514
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: How to get undo to work?

Post by sparr »

This is a terrible idea that only might work and would almost certainly cause more problems than it fixes:

instead of creating a wire, build_from_cursor a blueprint that contains the entities and the wire
ndh
Inserter
Inserter
Posts: 23
Joined: Sat Apr 29, 2023 7:19 pm
Contact:

Re: How to get undo to work?

Post by ndh »

This is a terrible idea...
Just a heads up, starting a post in this manner might set the wrong tone. :)

I don't care if it's terrible. The game doesn't seem to offer a clean way of letting mods undo things. The devs give mod authors the silent treatment. So anything that works is a good idea in my book.

I don't have time to test this today. But thank you for the suggestion!
robot256
Smart Inserter
Smart Inserter
Posts: 1217
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: How to get undo to work?

Post by robot256 »

ndh wrote: Sun Jun 22, 2025 12:18 pm
This is a terrible idea...
Just a heads up, starting a post in this manner might set the wrong tone. :)

I don't care if it's terrible. The game doesn't seem to offer a clean way of letting mods undo things. The devs give mod authors the silent treatment. So anything that works is a good idea in my book.

I don't have time to test this today. But thank you for the suggestion!
I understand how you read it that way, but I think sparr was calling their own idea terrible, not yours.
My mods: Multiple Unit Train Control, RGB Pipes, Shipping Containers, Rocket Log, Smart Artillery Wagons.
Maintainer of Auto Deconstruct, Cargo Ships, Vehicle Wagon, Honk, Shortwave.
ndh
Inserter
Inserter
Posts: 23
Joined: Sat Apr 29, 2023 7:19 pm
Contact:

Re: How to get undo to work?

Post by ndh »

Oh, yes, I realized this after reading. But it still gave me a bit of that sinking feeling when I first read it. :)

The intention was to say "The following might be a terrible idea, but...".
Post Reply

Return to “Modding discussion”