Undo/redo

Place to get help with not working mods / modding interface.
ndh
Inserter
Inserter
Posts: 29
Joined: Sat Apr 29, 2023 7:19 pm
Contact:

Undo/redo

Post by ndh »

How does it work? Is there any way for mod authors to use it?

Which API calls cause an item to get added to the Undo stack?
Bilka
Factorio Staff
Factorio Staff
Posts: 3405
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Undo/redo

Post by Bilka »

These questions are too broad to improve documentation based on this. Moved to modding help so people can try to help you anyway. If you have more specific things you'd like documented based on that, please let us know.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
ndh
Inserter
Inserter
Posts: 29
Joined: Sat Apr 29, 2023 7:19 pm
Contact:

Re: Undo/redo

Post by ndh »

No, I don't think so. My impression is that currently the API doesn't support Undo in general. It would be nice if this was officially acknowledged.
robot256
Smart Inserter
Smart Inserter
Posts: 1219
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: Undo/redo

Post by robot256 »

If I remember correctly, your question was about how to add an empty item to the undo stack that you could add things to later. The existing API lets you read and modify the undo and redo stacks, but does not let you create entries without invoking an action that emulates a player action that would create an undo item.

That "add undo item" is absent from the API indirectly communicates thay it is not possible. Maybe a direct statement would be better.
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.
Bilka
Factorio Staff
Factorio Staff
Posts: 3405
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Undo/redo

Post by Bilka »

You can access the stack here: https://lua-api.factorio.com/latest/cla ... redo_stack

You can add things to the stack with various methods that emulate player actions and some methods take player params to add the action to the undo/redo stack.

If you'd like the api changed, concrete suggestions with usecases in the modding interface request subforum are the way to go about requesting that. (But don't put too high hopes into it, a number of us don't like working with the undo/redo api either.)
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
ndh
Inserter
Inserter
Posts: 29
Joined: Sat Apr 29, 2023 7:19 pm
Contact:

Re: Undo/redo

Post by ndh »

Thank you! This is a good start.

I think this would be a great addition to the documentation at https://lua-api.factorio.com/latest/cla ... Stack.html then.
The undo queue for a player. The term item_index refers to the index of an undo item in the queue, while action_index refers to the index of one of the individual actions that make up an undo item.

It is not possible to directly add items to the undo queue. However, certain player actions (see https://lua-api.factorio.com/latest/cla ... layer.html) end up adding items to that player's undo queue. Some methods take a parameter of type LuaPlayer, and add an item to the undo queue.
Now the question remains which methods add items to the undo queue.

Suggestion: Ask a Copilot agent to go over your code base and add user-facing documentation to every API method that adds an item to the undo queue. Should be pretty straightforward for an LLM.
Post Reply

Return to “Modding help”