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.
How to get undo to work?
Re: How to get undo to work?
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
instead of creating a wire, build_from_cursor a blueprint that contains the entities and the wire
Re: How to get undo to work?
Just a heads up, starting a post in this manner might set the wrong tone.This is a terrible idea...

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!
Re: How to get undo to work?
I understand how you read it that way, but I think sparr was calling their own idea terrible, not yours.ndh wrote: Sun Jun 22, 2025 12:18 pmJust a heads up, starting a post in this manner might set the wrong tone.This is a terrible idea...
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!
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.
Maintainer of Auto Deconstruct, Cargo Ships, Vehicle Wagon, Honk, Shortwave.
Re: How to get undo to work?
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...".

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