Page 1 of 1

[2.0.60] Bad undo stack order in on_built callbacks of entity placement vs blueprint placement

Posted: Sun Aug 17, 2025 9:13 pm
by Loup&Snoop
The Reproduction and Bug
1) Listen to an on_built_entity event with the following in a control.lua:

Code: Select all

script.on_event(defines.events.on_built_entity, function(event)
	local player_index = event.player_index
	game.print("Before: " .. tostring(game.players[player_index].undo_redo_stack.get_undo_item_count()))
        event.entity.rotate{by_player=player_index}
        game.print("After: " .. tostring(game.players[player_index].undo_redo_stack.get_undo_item_count()))
end)
I recommend printing the size of the undo stack to see what is going on:
/c game.print("Current undo stack size: " .. tostring(game.players[1].undo_redo_stack.get_undo_item_count()))

Look! A super handy control.lua file for testing! Better download it before it has a chance to run away:
control.lua
(592 Bytes) Downloaded 35 times

With this code in (assuming you start with nothing in the undo stack):

Case 1:
-Place an inserter via cursor. It gets rotated when you place it.
-Code will print: Before: 0, After: 1. End with an undo stack size of 2.
-Undo stack now has the placement of the inserter on top, and the rotation on the bottom.
-Press undo once => Inserter destruction
-Press undo again => the command fizzles and does nothing

Case 2:
-Place a blueprint that is just an inserter. It gets rotated when you place it.
-Code will print: Before: 1, After: 2. End with an undo stack size of 2.
-Undo stack now has the rotation on the top, and the entity placement on the bottom.
-Press undo once => Inserter gets un-rotated
-Press undo again => Inserter destruction
Expected Behavior
I expect the undo stack to not depend on whether I'm placing things via blueprint or normal entity placement, when scripts are doing things in on_built_entity callbacks.

Re: [2.0.60] Bad undo stack order in on_built callbacks of entity placement vs blueprint placement

Posted: Mon Aug 18, 2025 10:47 pm
by Rseding91
Thanks for the report. This is now fixed for the next release.