Page 1 of 1

How to get undo to work?

Posted: Fri Jun 20, 2025 2:06 pm
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.

Re: How to get undo to work?

Posted: Fri Jun 20, 2025 7:09 pm
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

Re: How to get undo to work?

Posted: Sun Jun 22, 2025 12:18 pm
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!

Re: How to get undo to work?

Posted: Sun Jun 22, 2025 2:01 pm
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.

Re: How to get undo to work?

Posted: Mon Jun 23, 2025 1:44 pm
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...".