Page 1 of 1
Undo/redo
Posted: Sun Jun 22, 2025 12:20 pm
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?
Re: Undo/redo
Posted: Mon Jun 23, 2025 11:47 am
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.
Re: Undo/redo
Posted: Mon Jun 23, 2025 6:14 pm
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.
Re: Undo/redo
Posted: Mon Jun 23, 2025 6:20 pm
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.
Re: Undo/redo
Posted: Mon Jun 23, 2025 6:45 pm
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.)
Re: Undo/redo
Posted: Tue Jun 24, 2025 10:48 pm
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.