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?
Undo/redo
Re: Undo/redo
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.
Re: Undo/redo
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
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.
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.
Maintainer of Auto Deconstruct, Cargo Ships, Vehicle Wagon, Honk, Shortwave.
Re: Undo/redo
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.)
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.
Re: Undo/redo
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.
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.
I think this would be a great addition to the documentation at https://lua-api.factorio.com/latest/cla ... Stack.html then.
Now the question remains which methods add items to the undo queue.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.
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.